summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-09-19 19:42:07 +0000
committerDavid Robillard <d@drobilla.net>2011-09-19 19:42:07 +0000
commitdf3a3f7a838d920d416523d5875ef2b166abba9c (patch)
treeb40ad77f21c7eadedffce82b07271eebc27379af /test
parentaa6f685daa386f6d4eff353b8ade61e84c09f847 (diff)
downloadzix-df3a3f7a838d920d416523d5875ef2b166abba9c.tar.gz
zix-df3a3f7a838d920d416523d5875ef2b166abba9c.tar.bz2
zix-df3a3f7a838d920d416523d5875ef2b166abba9c.zip
Benchmark searching in random order
git-svn-id: http://svn.drobilla.net/zix/trunk@30 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
Diffstat (limited to 'test')
-rw-r--r--test/patree_bench.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/test/patree_bench.c b/test/patree_bench.c
index aca4d45..cdd40c8 100644
--- a/test/patree_bench.c
+++ b/test/patree_bench.c
@@ -26,6 +26,8 @@
#include "zix/patree.h"
#include "zix/fat_patree.h"
+const unsigned seed = 1;
+
static int
test_fail(const char* fmt, ...)
{
@@ -128,37 +130,43 @@ main(int argc, char** argv)
// Benchmark search
// GHashTable
+ srand(seed);
struct timespec search_start = bench_start();
for (size_t i = 0; i < n; ++i) {
- char* match = g_hash_table_lookup(hash, strings[i]);
- if (strcmp(match, strings[i])) {
- return test_fail("Bad match for `%s'\n", strings[i]);
+ const size_t index = rand() % n;
+ char* match = g_hash_table_lookup(hash, strings[index]);
+ if (strcmp(match, strings[index])) {
+ return test_fail("Bad match for `%s'\n", strings[index]);
}
}
fprintf(search_dat, "\t%lf", bench_end(&search_start));
// ZixPatree
+ srand(seed);
search_start = bench_start();
for (size_t i = 0; i < n; ++i) {
+ const size_t index = rand() % n;
char* match = NULL;
- if (zix_patree_find(patree, strings[i], &match)) {
- return test_fail("Patree: Failed to find `%s'\n", strings[i]);
+ if (zix_patree_find(patree, strings[index], &match)) {
+ return test_fail("Patree: Failed to find `%s'\n", strings[index]);
}
- if (strcmp(match, strings[i])) {
- return test_fail("Patree: Bad match for `%s'\n", strings[i]);
+ if (strcmp(match, strings[index])) {
+ return test_fail("Patree: Bad match for `%s'\n", strings[index]);
}
}
fprintf(search_dat, "\t%lf", bench_end(&search_start));
// ZixFatPatree
+ srand(seed);
search_start = bench_start();
for (size_t i = 0; i < n; ++i) {
+ const size_t index = rand() % n;
char* match = NULL;
- if (zix_fat_patree_find(fat_patree, strings[i], &match)) {
- return test_fail("FatPatree: Failed to find `%s'\n", strings[i]);
+ if (zix_fat_patree_find(fat_patree, strings[index], &match)) {
+ return test_fail("FatPatree: Failed to find `%s'\n", strings[index]);
}
- if (strcmp(match, strings[i])) {
- return test_fail("FatPatree: Bad match for `%s'\n", strings[i]);
+ if (strcmp(match, strings[index])) {
+ return test_fail("FatPatree: Bad match for `%s'\n", strings[index]);
}
}
fprintf(search_dat, "\t%lf\n", bench_end(&search_start));