diff options
author | David Robillard <d@drobilla.net> | 2007-08-05 07:02:39 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-08-05 07:02:39 +0000 |
commit | 63d4377a701b4f3280ea66646e29c33ce68aef08 (patch) | |
tree | 5463f36e6f7eed2da358415c919b01952c6c39b8 /tests | |
parent | f4fd64545cc0ddd3ef81f9b79e3568090860590a (diff) | |
download | raul-63d4377a701b4f3280ea66646e29c33ce68aef08.tar.gz raul-63d4377a701b4f3280ea66646e29c33ce68aef08.tar.bz2 raul-63d4377a701b4f3280ea66646e29c33ce68aef08.zip |
Yet more benchmarking.
git-svn-id: http://svn.drobilla.net/lad/raul@680 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/table_test.cpp | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/tests/table_test.cpp b/tests/table_test.cpp index c517db1..d411d12 100644 --- a/tests/table_test.cpp +++ b/tests/table_test.cpp @@ -2,11 +2,16 @@ #include <iostream> #include <utility> #include <map> +#include <set> +#include <tr1/unordered_map> #include <sys/time.h> #include <raul/PathTable.hpp> #include <raul/Table.hpp> #include <raul/TableImpl.hpp> +#define BOOST_MULTI_INDEX_DISABLE_SERIALIZATION 1 +#include <boost/functional/hash.hpp> + using namespace Raul; using namespace std; @@ -205,7 +210,7 @@ main(int argc, char** argv) string random_string() { - string ret(40, 'A' + (rand() % 26)); + string ret(60, 'A' + (rand() % 26)); return ret; } @@ -259,6 +264,33 @@ benchmark(size_t n) cout << "std::map time to lookup " << n << " values: \t" << delta_t << endl; + /** std::set **/ + + std::set<std::string> s; + + gettimeofday(&t1, NULL); + + for (size_t i=0; i < n; ++i) + s.insert(values[i]); + + gettimeofday(&t2, NULL); + + delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; + + cout << "std::set time to insert " << n << " values: \t" << delta_t << endl; + + gettimeofday(&t1, NULL); + + for (size_t i=0; i < n; ++i) + useless_accumulator += (int)(*s.find(values[i]))[0]; + + gettimeofday(&t2, NULL); + + delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; + + cout << "std::set time to lookup " << n << " values: \t" << delta_t << endl; + + /** sorted std::vector **/ /*std::vector<int> v; @@ -313,6 +345,34 @@ benchmark(size_t n) delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; cout << "Raul::Table time to lookup " << n << " values: \t" << delta_t << endl; + + + /** boost::hash && std::unordered_map **/ + + tr1::unordered_map<string, int, boost::hash<string> > um; + + gettimeofday(&t1, NULL); + + um.rehash(n); + + for (size_t i=0; i < n; ++i) + um.insert(make_pair(values[i], i)); + + gettimeofday(&t2, NULL); + + delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; + + cout << "tr1::unordered_map + boost::hash time to insert " << n << " values: \t" << delta_t << endl; + + gettimeofday(&t1, NULL); + + for (size_t i=0; i < n; ++i) + useless_accumulator += um.find(values[i])->second; + + gettimeofday(&t2, NULL); + + delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f; + cout << "tr1::unordered_map + boost::hash time to lookup " << n << " values: \t" << delta_t << endl; } |