From df3a3f7a838d920d416523d5875ef2b166abba9c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 19 Sep 2011 19:42:07 +0000 Subject: Benchmark searching in random order git-svn-id: http://svn.drobilla.net/zix/trunk@30 df6676b4-ccc9-40e5-b5d6-7c4628a128e3 --- test/patree_bench.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'test') 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)); -- cgit v1.2.1