summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-08-05 06:10:36 +0000
committerDavid Robillard <d@drobilla.net>2007-08-05 06:10:36 +0000
commit9f14a7d7cd2c8eb29af3e6cd4b6e06b71ca8c28a (patch)
treedcc1175cc475607a3ce0d24cb4f1ce78289c9a8e /tests
parent090b31c8012dab19d7666a96cb2d3c8b272bc885 (diff)
downloadraul-9f14a7d7cd2c8eb29af3e6cd4b6e06b71ca8c28a.tar.gz
raul-9f14a7d7cd2c8eb29af3e6cd4b6e06b71ca8c28a.tar.bz2
raul-9f14a7d7cd2c8eb29af3e6cd4b6e06b71ca8c28a.zip
Added benchmark proving Raul::Table is slower than std::map and thus a useless piece of crap.
Awesome. git-svn-id: http://svn.drobilla.net/lad/raul@678 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/table_test.cpp118
2 files changed, 118 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f18bcc9..0829d81 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
if BUILD_TESTS
-AM_CXXFLAGS = -I.. -lpthread @REDLAND_CFLAGS@ @GLIBMM_CFLAGS@ -DTABLE_SORT_DEBUG
+AM_CXXFLAGS = -I.. -lpthread @REDLAND_CFLAGS@ @GLIBMM_CFLAGS@# -DTABLE_SORT_DEBUG
ALL_LIBS = @REDLAND_LIBS@ @GLIBMM_LIBS@ ../src/libraul.la
noinst_PROGRAMS = \
diff --git a/tests/table_test.cpp b/tests/table_test.cpp
index 19fd576..3c1462d 100644
--- a/tests/table_test.cpp
+++ b/tests/table_test.cpp
@@ -1,6 +1,8 @@
#include <string>
#include <iostream>
#include <utility>
+#include <map>
+#include <sys/time.h>
#include <raul/PathTable.hpp>
#include <raul/Table.hpp>
#include <raul/TableImpl.hpp>
@@ -17,10 +19,17 @@ bool range_comparator(const int& a, const int& b)
return ret;
}
+void benchmark(size_t n);
int
-main()
+main(int argc, char** argv)
{
+ if (argc == 3 && !strcmp(argv[1], "-b")) {
+ benchmark(atoi(argv[2]));
+ return 0;
+ }
+
+ cout << "run with -b num_elems to benchmark" << endl;
srand(time(NULL));
range_end_val = rand()%10;
@@ -193,3 +202,110 @@ main()
return 0;
}
+
+void
+benchmark(size_t n)
+{
+ cout << "Benchmarking with n = " << n << endl;
+
+ int useless_accumulator = 0;
+
+ srand(time(NULL));
+
+ vector<int> values(n);
+ for (size_t i=0; i < n; ++i)
+ values.push_back(rand() % n*100);
+
+ timeval t1;
+ t1.tv_sec=0;
+ t1.tv_usec=0;
+
+ timeval t2;
+ t2.tv_sec=0;
+ t2.tv_usec=0;
+
+
+ /** std::map **/
+
+ std::map<int,int> m;
+
+ gettimeofday(&t1, NULL);
+
+ for (size_t i=0; i < n; ++i)
+ m.insert(make_pair(values[i], values[i]));
+
+ gettimeofday(&t2, NULL);
+
+ float delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f;
+
+ cout << "std::map time to insert " << n << " values: \t" << delta_t << endl;
+
+ gettimeofday(&t1, NULL);
+
+ for (size_t i=0; i < n; ++i)
+ useless_accumulator += m.find(values[i])->second;
+
+ gettimeofday(&t2, NULL);
+
+ delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f;
+
+ cout << "std::map time to lookup " << n << " values: \t" << delta_t << endl;
+
+
+ /** sorted std::vector **/
+
+ /*std::vector<int> v;
+
+ gettimeofday(&t1, NULL);
+
+ for (size_t i=0; i < n; ++i)
+ v.push_back(values[i]);
+
+ sort(v.begin(), v.end());
+
+ gettimeofday(&t2, NULL);
+
+ delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f;
+
+ cout << "std::vector (sorted) time to insert " << n << " values: \t" << delta_t << endl;
+
+ gettimeofday(&t1, NULL);
+
+ for (size_t i=0; i < n; ++i)
+ useless_accumulator += *lower_bound(v.begin(), v.end(), values[i]);
+
+ gettimeofday(&t2, NULL);
+
+ delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f;
+
+ cout << "std::vector (sorted) time to lookup " << n << " values: \t" << delta_t << endl;*/
+
+
+ /** Raul::Table **/
+
+ Raul::Table<int,int> t(n);
+
+ gettimeofday(&t1, NULL);
+
+ for (size_t i=0; i < n; ++i)
+ t.insert(make_pair(values[i], values[i]));
+
+ gettimeofday(&t2, NULL);
+
+ delta_t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) * 0.000001f;
+
+ cout << "Raul::Table time to insert " << n << " values: " << delta_t << endl;
+
+ gettimeofday(&t1, NULL);
+
+ for (size_t i=0; i < n; ++i)
+ useless_accumulator += t.find(values[i])->second;
+
+ gettimeofday(&t2, NULL);
+
+ 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;
+
+}
+