From a5ce8b6e080d30fc27dde15fbabab99c4909ea16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChangZhuo=20Chen=20=28=E9=99=B3=E6=98=8C=E5=80=AC=29?= Date: Wed, 21 May 2014 18:18:18 +0800 Subject: [PATCH 01/19] Add address sanitizer build to travis-ci --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index c7a1ad4..06e6e04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ matrix: env: CONFIGURE_OPTION='--enable-debug' COVERALLS=yes VALGRIND=no - compiler: gcc env: CONFIGURE_OPTION='--enable-debug' COVERALLS=yes VALGRIND=yes LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ + - compiler: clang + env: ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4 CFLAGS='-fsanitize=address -g -O1' install: - sudo apt-get update -qq From bd95ce9355f1506eb02e20a6f7ae44107de71847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChangZhuo=20Chen=20=28=E9=99=B3=E6=98=8C=E5=80=AC=29?= Date: Wed, 21 May 2014 19:44:46 +0800 Subject: [PATCH 02/19] Set llvm-symbolizer path --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 06e6e04..112a81c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ matrix: - compiler: gcc env: CONFIGURE_OPTION='--enable-debug' COVERALLS=yes VALGRIND=yes LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ - compiler: clang - env: ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4 CFLAGS='-fsanitize=address -g -O1' + env: ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/local/clang-3.4/bin/llvm-symbolizer CFLAGS='-fsanitize=address -g -O1' install: - sudo apt-get update -qq From 291e6add6bbddbd8f3bfb88a2aba95d3a2ccdd49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChangZhuo=20Chen=20=28=E9=99=B3=E6=98=8C=E5=80=AC=29?= Date: Thu, 22 May 2014 12:01:27 +0800 Subject: [PATCH 03/19] Use verbose make --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 112a81c..1c6a808 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,9 +25,9 @@ before_script: script: - ./autogen.sh - ./configure $CONFIGURE_OPTION - - make + - make V=1 - sudo make install - - if [ "x$VALGRIND" == xyes ]; then make check > /dev/null 2>&1; else make check; fi + - if [ "x$VALGRIND" == xyes ]; then make check > /dev/null 2>&1; else make check V=1; fi - if [ "x$VALGRIND" == xyes ]; then valgrind ./tests/.libs/* -v --trace-children=yes --show-leak-kinds=full --leak-check=full; fi after_success: From 7e44ee01f45b83214f54af1e48d9ebf635101468 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 16:59:40 +0800 Subject: [PATCH 04/19] refactor Benchmark related macros Conflicts: tests/bench_str.csv --- tests/bench.h | 32 ++++++++++++++++++-------------- tests/check_tree.c | 10 +++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/bench.h b/tests/bench.h index 27dd975..c4f691e 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -23,20 +23,6 @@ typedef struct { double end; } bench; - -#define BENCHMARK(name) \ - bench B; B.N = 5000000; B.R = 3; \ - bench_start(&B); \ - for (int _r = 0; _r < B.R ; _r++ ) { \ - for (int _i = 0; _i < B.N ; _i++ ) { - -#define END_BENCHMARK() \ - } \ - } \ - bench_stop(&B); - - - long unixtime(); double microtime(); @@ -49,4 +35,22 @@ double bench_iteration_speed(bench *b); void bench_print_summary(bench *b); +#define BENCHMARK(B) \ + bench B; B.N = 5000000; B.R = 3; \ + bench_start(&B); \ + for (int _r = 0; _r < B.R ; _r++ ) { \ + for (int _i = 0; _i < B.N ; _i++ ) { + +#define END_BENCHMARK(B) \ + } \ + } \ + bench_stop(&B); + +#define BENCHMARK_SUMMARY(B) bench_print_summary(&B); + +#define BENCHMARK_RECORD_CSV(B,filename) \ + FILE *fp = fopen(filename, "a+"); \ + fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start)); \ + fclose(fp); + #endif /* !BENCH_H */ diff --git a/tests/check_tree.c b/tests/check_tree.c index 72af3e1..88ebba1 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -720,14 +720,10 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL); printf("Benchmarking...\n"); BENCHMARK(string_dispatch) r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL); - END_BENCHMARK() - - bench_print_summary(&B); - - FILE *fp = fopen("bench_str.csv", "a+"); - fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start)); - fclose(fp); + END_BENCHMARK(string_dispatch) + BENCHMARK_SUMMARY(string_dispatch); + BENCHMARK_RECORD_CSV(string_dispatch, "bench_str.csv") } END_TEST From 3879316e087089969117d32099649a5c0ed14c88 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 17:03:33 +0800 Subject: [PATCH 05/19] Add bench_duration function Conflicts: tests/bench_str.csv --- tests/bench.c | 10 +++++++--- tests/bench.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/bench.c b/tests/bench.c index 494cd1a..c3ef66b 100644 --- a/tests/bench.c +++ b/tests/bench.c @@ -45,12 +45,16 @@ void bench_stop(bench *b) { } double bench_iteration_speed(bench *b) { - return b->N / (b->end - b->start); + return (b->N * b->R) / (b->end - b->start); +} + +double bench_duration(bench *b) { + return (b->end - b->start); } void bench_print_summary(bench *b) { printf("%ld runs, ", b->R); printf("%ld iterations each run, ", b->N); - printf("finished in %lf seconds\n", b->end - b->start ); - printf("%.2f i/sec\n", (b->N * b->R) / (b->end - b->start) ); + printf("finished in %lf seconds\n", bench_duration(b) ); + printf("%.2f i/sec\n", bench_iteration_speed(b) ); } diff --git a/tests/bench.h b/tests/bench.h index c4f691e..0d4c898 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -35,6 +35,8 @@ double bench_iteration_speed(bench *b); void bench_print_summary(bench *b); +double bench_duration(bench *b); + #define BENCHMARK(B) \ bench B; B.N = 5000000; B.R = 3; \ bench_start(&B); \ From 7f97440c725ff2d187cc372483600d8e5cb0ffae Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 20:48:01 +0800 Subject: [PATCH 06/19] Add bench_append_csv to combine multiple benchmark result in one entry --- tests/bench.c | 31 +++++++++++++++++++++++++++++-- tests/bench.h | 5 ++++- tests/bench_str.csv | 1 + 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/bench.c b/tests/bench.c index c3ef66b..84344f0 100644 --- a/tests/bench.c +++ b/tests/bench.c @@ -9,8 +9,9 @@ #include #include #include +#include /* va_list, va_start, va_arg, va_end */ -long unixtime() { +unsigned long unixtime() { struct timeval tp; long sec = 0L; if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) { @@ -35,7 +36,6 @@ double microtime() { return 0; } - void bench_start(bench *b) { b->start = microtime(); } @@ -58,3 +58,30 @@ void bench_print_summary(bench *b) { printf("finished in %lf seconds\n", bench_duration(b) ); printf("%.2f i/sec\n", bench_iteration_speed(b) ); } + +void bench_append_csv(char *filename, int countOfB, ...) { + FILE *fp = fopen(filename, "a+"); + if(!fp) { + return; + } + + unsigned long ts = unixtime(); + fprintf(fp, "%ld", ts); + + + int i; + bench * b; + va_list vl; + va_start(vl,countOfB); + for (i=0 ; i < countOfB ; i++) { + b = va_arg(vl, bench*); + fprintf(fp, ",%.2f", bench_iteration_speed(b) ); + } + va_end(vl); + + fprintf(fp, "\n"); + fclose(fp); +} + + + diff --git a/tests/bench.h b/tests/bench.h index 0d4c898..dbae90b 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -23,7 +23,7 @@ typedef struct { double end; } bench; -long unixtime(); +unsigned long unixtime(); double microtime(); @@ -37,6 +37,8 @@ void bench_print_summary(bench *b); double bench_duration(bench *b); +void bench_append_csv(char *filename, int countOfB, ...); + #define BENCHMARK(B) \ bench B; B.N = 5000000; B.R = 3; \ bench_start(&B); \ @@ -55,4 +57,5 @@ double bench_duration(bench *b); fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start)); \ fclose(fp); + #endif /* !BENCH_H */ diff --git a/tests/bench_str.csv b/tests/bench_str.csv index a10d1c5..79871fd 100644 --- a/tests/bench_str.csv +++ b/tests/bench_str.csv @@ -443,3 +443,4 @@ 1400668574,13632260.72 1400681414,10832905.89 1400685490,13185955.87 +1400762875,10472029.42 From c9fe373d91c954105f5f9c2dd42f46e45933f69c Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:01:25 +0800 Subject: [PATCH 07/19] benchmark function improvements --- tests/bench.c | 5 +++++ tests/bench.h | 8 +++----- tests/check_tree.c | 5 ++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/bench.c b/tests/bench.c index 84344f0..cebd3e5 100644 --- a/tests/bench.c +++ b/tests/bench.c @@ -59,6 +59,11 @@ void bench_print_summary(bench *b) { printf("%.2f i/sec\n", bench_iteration_speed(b) ); } +/** + * Combine multiple benchmark result into one measure entry. + * + * bench_append_csv("benchmark.csv", 3, &b1, &b2) + */ void bench_append_csv(char *filename, int countOfB, ...) { FILE *fp = fopen(filename, "a+"); if(!fp) { diff --git a/tests/bench.h b/tests/bench.h index dbae90b..85ba0bb 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -14,7 +14,6 @@ #define SEC_IN_MIN 60 #define NUL '\0' - typedef struct { long N; // N for each run long R; // runs @@ -41,6 +40,7 @@ void bench_append_csv(char *filename, int countOfB, ...); #define BENCHMARK(B) \ bench B; B.N = 5000000; B.R = 3; \ + printf("Benchmarking " #B "...\n"); \ bench_start(&B); \ for (int _r = 0; _r < B.R ; _r++ ) { \ for (int _i = 0; _i < B.N ; _i++ ) { @@ -52,10 +52,8 @@ void bench_append_csv(char *filename, int countOfB, ...); #define BENCHMARK_SUMMARY(B) bench_print_summary(&B); -#define BENCHMARK_RECORD_CSV(B,filename) \ - FILE *fp = fopen(filename, "a+"); \ - fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start)); \ - fclose(fp); +#define BENCHMARK_RECORD_CSV(filename, countOfB, ...) \ + bench_append_csv(filename, countOfB, __VA_ARGS__) #endif /* !BENCH_H */ diff --git a/tests/check_tree.c b/tests/check_tree.c index 88ebba1..9160e1d 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -717,13 +717,12 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL); ck_assert_int_eq( *((int*) m->data), 999 ); - printf("Benchmarking...\n"); BENCHMARK(string_dispatch) r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL); END_BENCHMARK(string_dispatch) - BENCHMARK_SUMMARY(string_dispatch); - BENCHMARK_RECORD_CSV(string_dispatch, "bench_str.csv") + + BENCHMARK_RECORD_CSV("bench_str.csv", 1, &string_dispatch); } END_TEST From fa6a7b77e0d561fd5f4b8ced1a68376ddb55f86c Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:18:17 +0800 Subject: [PATCH 08/19] Add pcre_benchmark test case --- tests/check_tree.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/check_tree.c b/tests/check_tree.c index 9160e1d..96271c5 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -362,10 +362,8 @@ END_TEST START_TEST(benchmark_str) { - match_entry * entry = match_entry_createl("/blog/post", strlen("/blog/post") ); node * n = r3_tree_create(1); - int route_data = 999; r3_tree_insert_path(n, "/foo/bar/baz", NULL); @@ -705,15 +703,11 @@ r3_tree_insert_path(n, "/garply/grault/qux", NULL); r3_tree_insert_path(n, "/garply/grault/quux", NULL); r3_tree_insert_path(n, "/garply/grault/corge", NULL); - r3_tree_compile(n); - // r3_tree_dump(n, 0); - // match_entry *entry = zcalloc( 1 ); node *m; m = r3_tree_match(n , "/qux/bar/corge", NULL); - fail_if( m == NULL ); - // r3_tree_dump( m, 0 ); + ck_assert(m != NULL); ck_assert_int_eq( *((int*) m->data), 999 ); @@ -722,7 +716,18 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL); END_BENCHMARK(string_dispatch) BENCHMARK_SUMMARY(string_dispatch); - BENCHMARK_RECORD_CSV("bench_str.csv", 1, &string_dispatch); + + node * tree2 = r3_tree_create(1); + r3_tree_insert_path(tree2, "/post/{year}/{month}", NULL); + r3_tree_compile(tree2); + + BENCHMARK(pcre_dispatch) + r3_tree_matchl(tree2, "/post/2014/12", strlen("/post/2014/12"), NULL); + END_BENCHMARK(pcre_dispatch) + BENCHMARK_SUMMARY(pcre_dispatch); + + + BENCHMARK_RECORD_CSV("bench_str.csv", 2, &string_dispatch, &pcre_dispatch); } END_TEST @@ -745,6 +750,7 @@ Suite* r3_suite (void) { tcase_add_test(tcase, test_pcre_patterns_insert_2); tcase_add_test(tcase, test_pcre_patterns_insert_3); tcase_add_test(tcase, benchmark_str); + tcase_set_timeout(tcase, 30); suite_add_tcase(suite, tcase); From ebf528281d166891ad771bb7d84291c20198012a Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:37:12 +0800 Subject: [PATCH 09/19] Add pcre benchmark to chart --- bench.html | 46 ++++++++++++++++++++++++++++++--------------- tests/bench_str.csv | 2 ++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/bench.html b/bench.html index d395786..f22304e 100644 --- a/bench.html +++ b/bench.html @@ -62,7 +62,8 @@ legend: { align: 'left', verticalAlign: 'top', - y: 20, + y: 50, + x: 100, floating: true, borderWidth: 0 }, @@ -73,6 +74,7 @@ }, plotOptions: { + /* area: { fillColor: { linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1}, @@ -92,28 +94,42 @@ }, threshold: null } + */ }, - series: [{ - type: 'area', - name: 'Speed', - pointInterval: 1000, - lineWidth: 2, - marker: { - radius: 3 + series: [ + { + type: 'area', + name: '/qux/bar/corge', + pointInterval: 1000, + lineWidth: 2, + marker: { + radius: 3 + }, + pointStart: Date.UTC(2014, 5, 16), + data: [] }, - pointStart: Date.UTC(2014, 5, 16), - data: [] - }] + { + type: 'area', + name: '/post/{year}/{month}', + pointInterval: 1000, + lineWidth: 2, + marker: { + radius: 3 + }, + pointStart: Date.UTC(2014, 5, 16), + data: [] + } + ] }; var lines = data.split(/\n/); $(lines).each(function(i,line) { var columns = line.split(/,/); - var i = parseInt(columns[1]); - if(i) { - options.series[0].data.push(i); - } + var str_i = parseInt(columns[1]); + var pcre_i = parseInt(columns[2]); + options.series[0].data.push(str_i || 0); + options.series[1].data.push(pcre_i || 0); }); $('#chart').highcharts(options); diff --git a/tests/bench_str.csv b/tests/bench_str.csv index 79871fd..0a99cd5 100644 --- a/tests/bench_str.csv +++ b/tests/bench_str.csv @@ -444,3 +444,5 @@ 1400681414,10832905.89 1400685490,13185955.87 1400762875,10472029.42 +1400764426,10066458.45,1590373.41 +1400765068,10657617.64,2131810.12 From 8cea8701f4693ace48f8fe1fce2b203ba5667e8d Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:37:36 +0800 Subject: [PATCH 10/19] set line-width to 1 --- bench.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench.html b/bench.html index f22304e..267ae8f 100644 --- a/bench.html +++ b/bench.html @@ -102,7 +102,7 @@ type: 'area', name: '/qux/bar/corge', pointInterval: 1000, - lineWidth: 2, + lineWidth: 1, marker: { radius: 3 }, @@ -113,7 +113,7 @@ type: 'area', name: '/post/{year}/{month}', pointInterval: 1000, - lineWidth: 2, + lineWidth: 1, marker: { radius: 3 }, From e165d8e27a5d804ec1fb140fad5e065807132097 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:38:46 +0800 Subject: [PATCH 11/19] update legend text --- bench.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench.html b/bench.html index 267ae8f..a772687 100644 --- a/bench.html +++ b/bench.html @@ -100,7 +100,7 @@ series: [ { type: 'area', - name: '/qux/bar/corge', + name: 'string matching', pointInterval: 1000, lineWidth: 1, marker: { From ce1f3cdc3fcf0900a656c72c3d5cf2343487f3e3 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:44:31 +0800 Subject: [PATCH 12/19] Update legend style --- bench.html | 9 +++++---- tests/bench.h | 1 + tests/check_tree.c | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bench.html b/bench.html index a772687..e62265b 100644 --- a/bench.html +++ b/bench.html @@ -60,12 +60,13 @@ }], legend: { - align: 'left', + align: 'right', verticalAlign: 'top', y: 50, - x: 100, - floating: true, - borderWidth: 0 + floating: false, + layout: 'vertical', + background: '#fff', + borderWidth: 1, }, tooltip: { diff --git a/tests/bench.h b/tests/bench.h index 85ba0bb..a47fa53 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -55,5 +55,6 @@ void bench_append_csv(char *filename, int countOfB, ...); #define BENCHMARK_RECORD_CSV(filename, countOfB, ...) \ bench_append_csv(filename, countOfB, __VA_ARGS__) +#define BR(b) &b; #endif /* !BENCH_H */ diff --git a/tests/check_tree.c b/tests/check_tree.c index 96271c5..2626484 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -703,7 +703,9 @@ r3_tree_insert_path(n, "/garply/grault/qux", NULL); r3_tree_insert_path(n, "/garply/grault/quux", NULL); r3_tree_insert_path(n, "/garply/grault/corge", NULL); + BENCHMARK(tree_compile) r3_tree_compile(n); + END_BENCHMARK(tree_compile) node *m; m = r3_tree_match(n , "/qux/bar/corge", NULL); @@ -727,7 +729,7 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL); BENCHMARK_SUMMARY(pcre_dispatch); - BENCHMARK_RECORD_CSV("bench_str.csv", 2, &string_dispatch, &pcre_dispatch); + BENCHMARK_RECORD_CSV("bench_str.csv", 2, BR(string_dispatch), BR(pcre_dispatch), BR(tree_compile) ); } END_TEST From fc1a4b762d3464365d8952da909f80103450e9c9 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:55:41 +0800 Subject: [PATCH 13/19] Separate benchmark application --- bench.html | 25 ++- tests/Makefile.am | 8 +- tests/bench.c | 384 +++++++++++++++++++++++++++++++++++++++++++- tests/bench.h | 10 +- tests/bench_str.csv | 2 + tests/check_tree.c | 376 ------------------------------------------- 6 files changed, 419 insertions(+), 386 deletions(-) diff --git a/bench.html b/bench.html index e62265b..7c44179 100644 --- a/bench.html +++ b/bench.html @@ -120,6 +120,17 @@ }, pointStart: Date.UTC(2014, 5, 16), data: [] + }, + { + type: 'area', + name: 'tree_compile', + pointInterval: 1000, + lineWidth: 1, + marker: { + radius: 3 + }, + pointStart: Date.UTC(2014, 5, 16), + data: [] } ] }; @@ -127,10 +138,16 @@ var lines = data.split(/\n/); $(lines).each(function(i,line) { var columns = line.split(/,/); - var str_i = parseInt(columns[1]); - var pcre_i = parseInt(columns[2]); - options.series[0].data.push(str_i || 0); - options.series[1].data.push(pcre_i || 0); + var a; + if (a = parseInt(columns[1])) { + options.series[0].data.push(a || 0); + } + if (a = parseInt(columns[2])) { + options.series[1].data.push(a || 0); + } + if (a = parseInt(columns[3])) { + options.series[2].data.push(a || 0); + } }); $('#chart').highcharts(options); diff --git a/tests/Makefile.am b/tests/Makefile.am index 21dd302..8edfa58 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,7 +23,7 @@ endif if ENABLE_GRAPHVIZ TESTS += check_gvc -check_gvc_SOURCES = check_gvc.c bench.c +check_gvc_SOURCES = check_gvc.c # check_gvc_LDADD = $(GVC_DEPS_LIBS) $(DEPS_LIBS) -L$(top_builddir)/src -lr3 @CHECK_LIBS@ # check_gvc_CFLAGS = $(GVC_DEPS_CFLAGS) $(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include @CHECK_CFLAGS@ AM_CFLAGS += $(GVC_DEPS_CFLAGS) @@ -31,9 +31,13 @@ AM_LDFLAGS += $(GVC_DEPS_LIBS) endif +bin_PROGRAMS = benchmark +benchmark_SOURCES = bench.c + + # noinst_PROGRAMS = $(TESTS) -check_tree_SOURCES = check_tree.c bench.c +check_tree_SOURCES = check_tree.c # check_tree_LDADD=$(DEPS_LIBS) -L$(top_builddir)/src -lr3 @CHECK_LIBS@ # check_tree_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include @CHECK_CFLAGS@ diff --git a/tests/bench.c b/tests/bench.c index cebd3e5..b92cd89 100644 --- a/tests/bench.c +++ b/tests/bench.c @@ -4,13 +4,20 @@ * * Distributed under terms of the MIT license. */ - -#include "bench.h" -#include +#include "config.h" #include +#include #include #include /* va_list, va_start, va_arg, va_end */ +#include "r3.h" +#include "r3_str.h" +#include "str_array.h" +#include "zmalloc.h" +#include "bench.h" + + + unsigned long unixtime() { struct timeval tp; long sec = 0L; @@ -90,3 +97,374 @@ void bench_append_csv(char *filename, int countOfB, ...) { +int main() +{ + node * n = r3_tree_create(1); + + int route_data = 999; + +r3_tree_insert_path(n, "/foo/bar/baz", NULL); +r3_tree_insert_path(n, "/foo/bar/qux", NULL); +r3_tree_insert_path(n, "/foo/bar/quux", NULL); +r3_tree_insert_path(n, "/foo/bar/corge", NULL); +r3_tree_insert_path(n, "/foo/bar/grault", NULL); +r3_tree_insert_path(n, "/foo/bar/garply", NULL); +r3_tree_insert_path(n, "/foo/baz/bar", NULL); +r3_tree_insert_path(n, "/foo/baz/qux", NULL); +r3_tree_insert_path(n, "/foo/baz/quux", NULL); +r3_tree_insert_path(n, "/foo/baz/corge", NULL); +r3_tree_insert_path(n, "/foo/baz/grault", NULL); +r3_tree_insert_path(n, "/foo/baz/garply", NULL); +r3_tree_insert_path(n, "/foo/qux/bar", NULL); +r3_tree_insert_path(n, "/foo/qux/baz", NULL); +r3_tree_insert_path(n, "/foo/qux/quux", NULL); +r3_tree_insert_path(n, "/foo/qux/corge", NULL); +r3_tree_insert_path(n, "/foo/qux/grault", NULL); +r3_tree_insert_path(n, "/foo/qux/garply", NULL); +r3_tree_insert_path(n, "/foo/quux/bar", NULL); +r3_tree_insert_path(n, "/foo/quux/baz", NULL); +r3_tree_insert_path(n, "/foo/quux/qux", NULL); +r3_tree_insert_path(n, "/foo/quux/corge", NULL); +r3_tree_insert_path(n, "/foo/quux/grault", NULL); +r3_tree_insert_path(n, "/foo/quux/garply", NULL); +r3_tree_insert_path(n, "/foo/corge/bar", NULL); +r3_tree_insert_path(n, "/foo/corge/baz", NULL); +r3_tree_insert_path(n, "/foo/corge/qux", NULL); +r3_tree_insert_path(n, "/foo/corge/quux", NULL); +r3_tree_insert_path(n, "/foo/corge/grault", NULL); +r3_tree_insert_path(n, "/foo/corge/garply", NULL); +r3_tree_insert_path(n, "/foo/grault/bar", NULL); +r3_tree_insert_path(n, "/foo/grault/baz", NULL); +r3_tree_insert_path(n, "/foo/grault/qux", NULL); +r3_tree_insert_path(n, "/foo/grault/quux", NULL); +r3_tree_insert_path(n, "/foo/grault/corge", NULL); +r3_tree_insert_path(n, "/foo/grault/garply", NULL); +r3_tree_insert_path(n, "/foo/garply/bar", NULL); +r3_tree_insert_path(n, "/foo/garply/baz", NULL); +r3_tree_insert_path(n, "/foo/garply/qux", NULL); +r3_tree_insert_path(n, "/foo/garply/quux", NULL); +r3_tree_insert_path(n, "/foo/garply/corge", NULL); +r3_tree_insert_path(n, "/foo/garply/grault", NULL); +r3_tree_insert_path(n, "/bar/foo/baz", NULL); +r3_tree_insert_path(n, "/bar/foo/qux", NULL); +r3_tree_insert_path(n, "/bar/foo/quux", NULL); +r3_tree_insert_path(n, "/bar/foo/corge", NULL); +r3_tree_insert_path(n, "/bar/foo/grault", NULL); +r3_tree_insert_path(n, "/bar/foo/garply", NULL); +r3_tree_insert_path(n, "/bar/baz/foo", NULL); +r3_tree_insert_path(n, "/bar/baz/qux", NULL); +r3_tree_insert_path(n, "/bar/baz/quux", NULL); +r3_tree_insert_path(n, "/bar/baz/corge", NULL); +r3_tree_insert_path(n, "/bar/baz/grault", NULL); +r3_tree_insert_path(n, "/bar/baz/garply", NULL); +r3_tree_insert_path(n, "/bar/qux/foo", NULL); +r3_tree_insert_path(n, "/bar/qux/baz", NULL); +r3_tree_insert_path(n, "/bar/qux/quux", NULL); +r3_tree_insert_path(n, "/bar/qux/corge", NULL); +r3_tree_insert_path(n, "/bar/qux/grault", NULL); +r3_tree_insert_path(n, "/bar/qux/garply", NULL); +r3_tree_insert_path(n, "/bar/quux/foo", NULL); +r3_tree_insert_path(n, "/bar/quux/baz", NULL); +r3_tree_insert_path(n, "/bar/quux/qux", NULL); +r3_tree_insert_path(n, "/bar/quux/corge", NULL); +r3_tree_insert_path(n, "/bar/quux/grault", NULL); +r3_tree_insert_path(n, "/bar/quux/garply", NULL); +r3_tree_insert_path(n, "/bar/corge/foo", NULL); +r3_tree_insert_path(n, "/bar/corge/baz", NULL); +r3_tree_insert_path(n, "/bar/corge/qux", NULL); +r3_tree_insert_path(n, "/bar/corge/quux", NULL); +r3_tree_insert_path(n, "/bar/corge/grault", NULL); +r3_tree_insert_path(n, "/bar/corge/garply", NULL); +r3_tree_insert_path(n, "/bar/grault/foo", NULL); +r3_tree_insert_path(n, "/bar/grault/baz", NULL); +r3_tree_insert_path(n, "/bar/grault/qux", NULL); +r3_tree_insert_path(n, "/bar/grault/quux", NULL); +r3_tree_insert_path(n, "/bar/grault/corge", NULL); +r3_tree_insert_path(n, "/bar/grault/garply", NULL); +r3_tree_insert_path(n, "/bar/garply/foo", NULL); +r3_tree_insert_path(n, "/bar/garply/baz", NULL); +r3_tree_insert_path(n, "/bar/garply/qux", NULL); +r3_tree_insert_path(n, "/bar/garply/quux", NULL); +r3_tree_insert_path(n, "/bar/garply/corge", NULL); +r3_tree_insert_path(n, "/bar/garply/grault", NULL); +r3_tree_insert_path(n, "/baz/foo/bar", NULL); +r3_tree_insert_path(n, "/baz/foo/qux", NULL); +r3_tree_insert_path(n, "/baz/foo/quux", NULL); +r3_tree_insert_path(n, "/baz/foo/corge", NULL); +r3_tree_insert_path(n, "/baz/foo/grault", NULL); +r3_tree_insert_path(n, "/baz/foo/garply", NULL); +r3_tree_insert_path(n, "/baz/bar/foo", NULL); +r3_tree_insert_path(n, "/baz/bar/qux", NULL); +r3_tree_insert_path(n, "/baz/bar/quux", NULL); +r3_tree_insert_path(n, "/baz/bar/corge", NULL); +r3_tree_insert_path(n, "/baz/bar/grault", NULL); +r3_tree_insert_path(n, "/baz/bar/garply", NULL); +r3_tree_insert_path(n, "/baz/qux/foo", NULL); +r3_tree_insert_path(n, "/baz/qux/bar", NULL); +r3_tree_insert_path(n, "/baz/qux/quux", NULL); +r3_tree_insert_path(n, "/baz/qux/corge", NULL); +r3_tree_insert_path(n, "/baz/qux/grault", NULL); +r3_tree_insert_path(n, "/baz/qux/garply", NULL); +r3_tree_insert_path(n, "/baz/quux/foo", NULL); +r3_tree_insert_path(n, "/baz/quux/bar", NULL); +r3_tree_insert_path(n, "/baz/quux/qux", NULL); +r3_tree_insert_path(n, "/baz/quux/corge", NULL); +r3_tree_insert_path(n, "/baz/quux/grault", NULL); +r3_tree_insert_path(n, "/baz/quux/garply", NULL); +r3_tree_insert_path(n, "/baz/corge/foo", NULL); +r3_tree_insert_path(n, "/baz/corge/bar", NULL); +r3_tree_insert_path(n, "/baz/corge/qux", NULL); +r3_tree_insert_path(n, "/baz/corge/quux", NULL); +r3_tree_insert_path(n, "/baz/corge/grault", NULL); +r3_tree_insert_path(n, "/baz/corge/garply", NULL); +r3_tree_insert_path(n, "/baz/grault/foo", NULL); +r3_tree_insert_path(n, "/baz/grault/bar", NULL); +r3_tree_insert_path(n, "/baz/grault/qux", NULL); +r3_tree_insert_path(n, "/baz/grault/quux", NULL); +r3_tree_insert_path(n, "/baz/grault/corge", NULL); +r3_tree_insert_path(n, "/baz/grault/garply", NULL); +r3_tree_insert_path(n, "/baz/garply/foo", NULL); +r3_tree_insert_path(n, "/baz/garply/bar", NULL); +r3_tree_insert_path(n, "/baz/garply/qux", NULL); +r3_tree_insert_path(n, "/baz/garply/quux", NULL); +r3_tree_insert_path(n, "/baz/garply/corge", NULL); +r3_tree_insert_path(n, "/baz/garply/grault", NULL); +r3_tree_insert_path(n, "/qux/foo/bar", NULL); +r3_tree_insert_path(n, "/qux/foo/baz", NULL); +r3_tree_insert_path(n, "/qux/foo/quux", NULL); +r3_tree_insert_path(n, "/qux/foo/corge", NULL); +r3_tree_insert_path(n, "/qux/foo/grault", NULL); +r3_tree_insert_path(n, "/qux/foo/garply", NULL); +r3_tree_insert_path(n, "/qux/bar/foo", NULL); +r3_tree_insert_path(n, "/qux/bar/baz", NULL); +r3_tree_insert_path(n, "/qux/bar/quux", NULL); +r3_tree_insert_path(n, "/qux/bar/corge", &route_data); +r3_tree_insert_path(n, "/qux/bar/grault", NULL); +r3_tree_insert_path(n, "/qux/bar/garply", NULL); +r3_tree_insert_path(n, "/qux/baz/foo", NULL); +r3_tree_insert_path(n, "/qux/baz/bar", NULL); +r3_tree_insert_path(n, "/qux/baz/quux", NULL); +r3_tree_insert_path(n, "/qux/baz/corge", NULL); +r3_tree_insert_path(n, "/qux/baz/grault", NULL); +r3_tree_insert_path(n, "/qux/baz/garply", NULL); +r3_tree_insert_path(n, "/qux/quux/foo", NULL); +r3_tree_insert_path(n, "/qux/quux/bar", NULL); +r3_tree_insert_path(n, "/qux/quux/baz", NULL); +r3_tree_insert_path(n, "/qux/quux/corge", NULL); +r3_tree_insert_path(n, "/qux/quux/grault", NULL); +r3_tree_insert_path(n, "/qux/quux/garply", NULL); +r3_tree_insert_path(n, "/qux/corge/foo", NULL); +r3_tree_insert_path(n, "/qux/corge/bar", NULL); +r3_tree_insert_path(n, "/qux/corge/baz", NULL); +r3_tree_insert_path(n, "/qux/corge/quux", NULL); +r3_tree_insert_path(n, "/qux/corge/grault", NULL); +r3_tree_insert_path(n, "/qux/corge/garply", NULL); +r3_tree_insert_path(n, "/qux/grault/foo", NULL); +r3_tree_insert_path(n, "/qux/grault/bar", NULL); +r3_tree_insert_path(n, "/qux/grault/baz", NULL); +r3_tree_insert_path(n, "/qux/grault/quux", NULL); +r3_tree_insert_path(n, "/qux/grault/corge", NULL); +r3_tree_insert_path(n, "/qux/grault/garply", NULL); +r3_tree_insert_path(n, "/qux/garply/foo", NULL); +r3_tree_insert_path(n, "/qux/garply/bar", NULL); +r3_tree_insert_path(n, "/qux/garply/baz", NULL); +r3_tree_insert_path(n, "/qux/garply/quux", NULL); +r3_tree_insert_path(n, "/qux/garply/corge", NULL); +r3_tree_insert_path(n, "/qux/garply/grault", NULL); +r3_tree_insert_path(n, "/quux/foo/bar", NULL); +r3_tree_insert_path(n, "/quux/foo/baz", NULL); +r3_tree_insert_path(n, "/quux/foo/qux", NULL); +r3_tree_insert_path(n, "/quux/foo/corge", NULL); +r3_tree_insert_path(n, "/quux/foo/grault", NULL); +r3_tree_insert_path(n, "/quux/foo/garply", NULL); +r3_tree_insert_path(n, "/quux/bar/foo", NULL); +r3_tree_insert_path(n, "/quux/bar/baz", NULL); +r3_tree_insert_path(n, "/quux/bar/qux", NULL); +r3_tree_insert_path(n, "/quux/bar/corge", NULL); +r3_tree_insert_path(n, "/quux/bar/grault", NULL); +r3_tree_insert_path(n, "/quux/bar/garply", NULL); +r3_tree_insert_path(n, "/quux/baz/foo", NULL); +r3_tree_insert_path(n, "/quux/baz/bar", NULL); +r3_tree_insert_path(n, "/quux/baz/qux", NULL); +r3_tree_insert_path(n, "/quux/baz/corge", NULL); +r3_tree_insert_path(n, "/quux/baz/grault", NULL); +r3_tree_insert_path(n, "/quux/baz/garply", NULL); +r3_tree_insert_path(n, "/quux/qux/foo", NULL); +r3_tree_insert_path(n, "/quux/qux/bar", NULL); +r3_tree_insert_path(n, "/quux/qux/baz", NULL); +r3_tree_insert_path(n, "/quux/qux/corge", NULL); +r3_tree_insert_path(n, "/quux/qux/grault", NULL); +r3_tree_insert_path(n, "/quux/qux/garply", NULL); +r3_tree_insert_path(n, "/quux/corge/foo", NULL); +r3_tree_insert_path(n, "/quux/corge/bar", NULL); +r3_tree_insert_path(n, "/quux/corge/baz", NULL); +r3_tree_insert_path(n, "/quux/corge/qux", NULL); +r3_tree_insert_path(n, "/quux/corge/grault", NULL); +r3_tree_insert_path(n, "/quux/corge/garply", NULL); +r3_tree_insert_path(n, "/quux/grault/foo", NULL); +r3_tree_insert_path(n, "/quux/grault/bar", NULL); +r3_tree_insert_path(n, "/quux/grault/baz", NULL); +r3_tree_insert_path(n, "/quux/grault/qux", NULL); +r3_tree_insert_path(n, "/quux/grault/corge", NULL); +r3_tree_insert_path(n, "/quux/grault/garply", NULL); +r3_tree_insert_path(n, "/quux/garply/foo", NULL); +r3_tree_insert_path(n, "/quux/garply/bar", NULL); +r3_tree_insert_path(n, "/quux/garply/baz", NULL); +r3_tree_insert_path(n, "/quux/garply/qux", NULL); +r3_tree_insert_path(n, "/quux/garply/corge", NULL); +r3_tree_insert_path(n, "/quux/garply/grault", NULL); +r3_tree_insert_path(n, "/corge/foo/bar", NULL); +r3_tree_insert_path(n, "/corge/foo/baz", NULL); +r3_tree_insert_path(n, "/corge/foo/qux", NULL); +r3_tree_insert_path(n, "/corge/foo/quux", NULL); +r3_tree_insert_path(n, "/corge/foo/grault", NULL); +r3_tree_insert_path(n, "/corge/foo/garply", NULL); +r3_tree_insert_path(n, "/corge/bar/foo", NULL); +r3_tree_insert_path(n, "/corge/bar/baz", NULL); +r3_tree_insert_path(n, "/corge/bar/qux", NULL); +r3_tree_insert_path(n, "/corge/bar/quux", NULL); +r3_tree_insert_path(n, "/corge/bar/grault", NULL); +r3_tree_insert_path(n, "/corge/bar/garply", NULL); +r3_tree_insert_path(n, "/corge/baz/foo", NULL); +r3_tree_insert_path(n, "/corge/baz/bar", NULL); +r3_tree_insert_path(n, "/corge/baz/qux", NULL); +r3_tree_insert_path(n, "/corge/baz/quux", NULL); +r3_tree_insert_path(n, "/corge/baz/grault", NULL); +r3_tree_insert_path(n, "/corge/baz/garply", NULL); +r3_tree_insert_path(n, "/corge/qux/foo", NULL); +r3_tree_insert_path(n, "/corge/qux/bar", NULL); +r3_tree_insert_path(n, "/corge/qux/baz", NULL); +r3_tree_insert_path(n, "/corge/qux/quux", NULL); +r3_tree_insert_path(n, "/corge/qux/grault", NULL); +r3_tree_insert_path(n, "/corge/qux/garply", NULL); +r3_tree_insert_path(n, "/corge/quux/foo", NULL); +r3_tree_insert_path(n, "/corge/quux/bar", NULL); +r3_tree_insert_path(n, "/corge/quux/baz", NULL); +r3_tree_insert_path(n, "/corge/quux/qux", NULL); +r3_tree_insert_path(n, "/corge/quux/grault", NULL); +r3_tree_insert_path(n, "/corge/quux/garply", NULL); +r3_tree_insert_path(n, "/corge/grault/foo", NULL); +r3_tree_insert_path(n, "/corge/grault/bar", NULL); +r3_tree_insert_path(n, "/corge/grault/baz", NULL); +r3_tree_insert_path(n, "/corge/grault/qux", NULL); +r3_tree_insert_path(n, "/corge/grault/quux", NULL); +r3_tree_insert_path(n, "/corge/grault/garply", NULL); +r3_tree_insert_path(n, "/corge/garply/foo", NULL); +r3_tree_insert_path(n, "/corge/garply/bar", NULL); +r3_tree_insert_path(n, "/corge/garply/baz", NULL); +r3_tree_insert_path(n, "/corge/garply/qux", NULL); +r3_tree_insert_path(n, "/corge/garply/quux", NULL); +r3_tree_insert_path(n, "/corge/garply/grault", NULL); +r3_tree_insert_path(n, "/grault/foo/bar", NULL); +r3_tree_insert_path(n, "/grault/foo/baz", NULL); +r3_tree_insert_path(n, "/grault/foo/qux", NULL); +r3_tree_insert_path(n, "/grault/foo/quux", NULL); +r3_tree_insert_path(n, "/grault/foo/corge", NULL); +r3_tree_insert_path(n, "/grault/foo/garply", NULL); +r3_tree_insert_path(n, "/grault/bar/foo", NULL); +r3_tree_insert_path(n, "/grault/bar/baz", NULL); +r3_tree_insert_path(n, "/grault/bar/qux", NULL); +r3_tree_insert_path(n, "/grault/bar/quux", NULL); +r3_tree_insert_path(n, "/grault/bar/corge", NULL); +r3_tree_insert_path(n, "/grault/bar/garply", NULL); +r3_tree_insert_path(n, "/grault/baz/foo", NULL); +r3_tree_insert_path(n, "/grault/baz/bar", NULL); +r3_tree_insert_path(n, "/grault/baz/qux", NULL); +r3_tree_insert_path(n, "/grault/baz/quux", NULL); +r3_tree_insert_path(n, "/grault/baz/corge", NULL); +r3_tree_insert_path(n, "/grault/baz/garply", NULL); +r3_tree_insert_path(n, "/grault/qux/foo", NULL); +r3_tree_insert_path(n, "/grault/qux/bar", NULL); +r3_tree_insert_path(n, "/grault/qux/baz", NULL); +r3_tree_insert_path(n, "/grault/qux/quux", NULL); +r3_tree_insert_path(n, "/grault/qux/corge", NULL); +r3_tree_insert_path(n, "/grault/qux/garply", NULL); +r3_tree_insert_path(n, "/grault/quux/foo", NULL); +r3_tree_insert_path(n, "/grault/quux/bar", NULL); +r3_tree_insert_path(n, "/grault/quux/baz", NULL); +r3_tree_insert_path(n, "/grault/quux/qux", NULL); +r3_tree_insert_path(n, "/grault/quux/corge", NULL); +r3_tree_insert_path(n, "/grault/quux/garply", NULL); +r3_tree_insert_path(n, "/grault/corge/foo", NULL); +r3_tree_insert_path(n, "/grault/corge/bar", NULL); +r3_tree_insert_path(n, "/grault/corge/baz", NULL); +r3_tree_insert_path(n, "/grault/corge/qux", NULL); +r3_tree_insert_path(n, "/grault/corge/quux", NULL); +r3_tree_insert_path(n, "/grault/corge/garply", NULL); +r3_tree_insert_path(n, "/grault/garply/foo", NULL); +r3_tree_insert_path(n, "/grault/garply/bar", NULL); +r3_tree_insert_path(n, "/grault/garply/baz", NULL); +r3_tree_insert_path(n, "/grault/garply/qux", NULL); +r3_tree_insert_path(n, "/grault/garply/quux", NULL); +r3_tree_insert_path(n, "/grault/garply/corge", NULL); +r3_tree_insert_path(n, "/garply/foo/bar", NULL); +r3_tree_insert_path(n, "/garply/foo/baz", NULL); +r3_tree_insert_path(n, "/garply/foo/qux", NULL); +r3_tree_insert_path(n, "/garply/foo/quux", NULL); +r3_tree_insert_path(n, "/garply/foo/corge", NULL); +r3_tree_insert_path(n, "/garply/foo/grault", NULL); +r3_tree_insert_path(n, "/garply/bar/foo", NULL); +r3_tree_insert_path(n, "/garply/bar/baz", NULL); +r3_tree_insert_path(n, "/garply/bar/qux", NULL); +r3_tree_insert_path(n, "/garply/bar/quux", NULL); +r3_tree_insert_path(n, "/garply/bar/corge", NULL); +r3_tree_insert_path(n, "/garply/bar/grault", NULL); +r3_tree_insert_path(n, "/garply/baz/foo", NULL); +r3_tree_insert_path(n, "/garply/baz/bar", NULL); +r3_tree_insert_path(n, "/garply/baz/qux", NULL); +r3_tree_insert_path(n, "/garply/baz/quux", NULL); +r3_tree_insert_path(n, "/garply/baz/corge", NULL); +r3_tree_insert_path(n, "/garply/baz/grault", NULL); +r3_tree_insert_path(n, "/garply/qux/foo", NULL); +r3_tree_insert_path(n, "/garply/qux/bar", NULL); +r3_tree_insert_path(n, "/garply/qux/baz", NULL); +r3_tree_insert_path(n, "/garply/qux/quux", NULL); +r3_tree_insert_path(n, "/garply/qux/corge", NULL); +r3_tree_insert_path(n, "/garply/qux/grault", NULL); +r3_tree_insert_path(n, "/garply/quux/foo", NULL); +r3_tree_insert_path(n, "/garply/quux/bar", NULL); +r3_tree_insert_path(n, "/garply/quux/baz", NULL); +r3_tree_insert_path(n, "/garply/quux/qux", NULL); +r3_tree_insert_path(n, "/garply/quux/corge", NULL); +r3_tree_insert_path(n, "/garply/quux/grault", NULL); +r3_tree_insert_path(n, "/garply/corge/foo", NULL); +r3_tree_insert_path(n, "/garply/corge/bar", NULL); +r3_tree_insert_path(n, "/garply/corge/baz", NULL); +r3_tree_insert_path(n, "/garply/corge/qux", NULL); +r3_tree_insert_path(n, "/garply/corge/quux", NULL); +r3_tree_insert_path(n, "/garply/corge/grault", NULL); +r3_tree_insert_path(n, "/garply/grault/foo", NULL); +r3_tree_insert_path(n, "/garply/grault/bar", NULL); +r3_tree_insert_path(n, "/garply/grault/baz", NULL); +r3_tree_insert_path(n, "/garply/grault/qux", NULL); +r3_tree_insert_path(n, "/garply/grault/quux", NULL); +r3_tree_insert_path(n, "/garply/grault/corge", NULL); + + MEASURE(tree_compile) + r3_tree_compile(n); + END_MEASURE(tree_compile) + + node *m; + m = r3_tree_match(n , "/qux/bar/corge", NULL); + assert(m != NULL); + assert( *((int*) m->data) == 999 ); + + + BENCHMARK(string_dispatch) + r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL); + END_BENCHMARK(string_dispatch) + BENCHMARK_SUMMARY(string_dispatch); + + + node * tree2 = r3_tree_create(1); + r3_tree_insert_path(tree2, "/post/{year}/{month}", NULL); + r3_tree_compile(tree2); + + BENCHMARK(pcre_dispatch) + r3_tree_matchl(tree2, "/post/2014/12", strlen("/post/2014/12"), NULL); + END_BENCHMARK(pcre_dispatch) + BENCHMARK_SUMMARY(pcre_dispatch); + + BENCHMARK_RECORD_CSV("bench_str.csv", 3, BR(string_dispatch), BR(pcre_dispatch), BR(tree_compile) ); + return 0; +} diff --git a/tests/bench.h b/tests/bench.h index a47fa53..6b00f6c 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -38,6 +38,14 @@ double bench_duration(bench *b); void bench_append_csv(char *filename, int countOfB, ...); +#define MEASURE(B) \ + bench B; B.N = 1; B.R = 1; \ + printf("Measuring " #B "...\n"); \ + bench_start(&B); + +#define END_MEASURE(B) \ + bench_stop(&B); + #define BENCHMARK(B) \ bench B; B.N = 5000000; B.R = 3; \ printf("Benchmarking " #B "...\n"); \ @@ -55,6 +63,6 @@ void bench_append_csv(char *filename, int countOfB, ...); #define BENCHMARK_RECORD_CSV(filename, countOfB, ...) \ bench_append_csv(filename, countOfB, __VA_ARGS__) -#define BR(b) &b; +#define BR(b) &b #endif /* !BENCH_H */ diff --git a/tests/bench_str.csv b/tests/bench_str.csv index 0a99cd5..6dede90 100644 --- a/tests/bench_str.csv +++ b/tests/bench_str.csv @@ -446,3 +446,5 @@ 1400762875,10472029.42 1400764426,10066458.45,1590373.41 1400765068,10657617.64,2131810.12 +1400766518,10259200.94,1878279.25,96697.86 +1400766623,11057429.08,2113683.19,95835.70 diff --git a/tests/check_tree.c b/tests/check_tree.c index 2626484..c3d97fa 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -359,381 +359,6 @@ START_TEST(test_insert_route) END_TEST - -START_TEST(benchmark_str) -{ - node * n = r3_tree_create(1); - - int route_data = 999; - -r3_tree_insert_path(n, "/foo/bar/baz", NULL); -r3_tree_insert_path(n, "/foo/bar/qux", NULL); -r3_tree_insert_path(n, "/foo/bar/quux", NULL); -r3_tree_insert_path(n, "/foo/bar/corge", NULL); -r3_tree_insert_path(n, "/foo/bar/grault", NULL); -r3_tree_insert_path(n, "/foo/bar/garply", NULL); -r3_tree_insert_path(n, "/foo/baz/bar", NULL); -r3_tree_insert_path(n, "/foo/baz/qux", NULL); -r3_tree_insert_path(n, "/foo/baz/quux", NULL); -r3_tree_insert_path(n, "/foo/baz/corge", NULL); -r3_tree_insert_path(n, "/foo/baz/grault", NULL); -r3_tree_insert_path(n, "/foo/baz/garply", NULL); -r3_tree_insert_path(n, "/foo/qux/bar", NULL); -r3_tree_insert_path(n, "/foo/qux/baz", NULL); -r3_tree_insert_path(n, "/foo/qux/quux", NULL); -r3_tree_insert_path(n, "/foo/qux/corge", NULL); -r3_tree_insert_path(n, "/foo/qux/grault", NULL); -r3_tree_insert_path(n, "/foo/qux/garply", NULL); -r3_tree_insert_path(n, "/foo/quux/bar", NULL); -r3_tree_insert_path(n, "/foo/quux/baz", NULL); -r3_tree_insert_path(n, "/foo/quux/qux", NULL); -r3_tree_insert_path(n, "/foo/quux/corge", NULL); -r3_tree_insert_path(n, "/foo/quux/grault", NULL); -r3_tree_insert_path(n, "/foo/quux/garply", NULL); -r3_tree_insert_path(n, "/foo/corge/bar", NULL); -r3_tree_insert_path(n, "/foo/corge/baz", NULL); -r3_tree_insert_path(n, "/foo/corge/qux", NULL); -r3_tree_insert_path(n, "/foo/corge/quux", NULL); -r3_tree_insert_path(n, "/foo/corge/grault", NULL); -r3_tree_insert_path(n, "/foo/corge/garply", NULL); -r3_tree_insert_path(n, "/foo/grault/bar", NULL); -r3_tree_insert_path(n, "/foo/grault/baz", NULL); -r3_tree_insert_path(n, "/foo/grault/qux", NULL); -r3_tree_insert_path(n, "/foo/grault/quux", NULL); -r3_tree_insert_path(n, "/foo/grault/corge", NULL); -r3_tree_insert_path(n, "/foo/grault/garply", NULL); -r3_tree_insert_path(n, "/foo/garply/bar", NULL); -r3_tree_insert_path(n, "/foo/garply/baz", NULL); -r3_tree_insert_path(n, "/foo/garply/qux", NULL); -r3_tree_insert_path(n, "/foo/garply/quux", NULL); -r3_tree_insert_path(n, "/foo/garply/corge", NULL); -r3_tree_insert_path(n, "/foo/garply/grault", NULL); -r3_tree_insert_path(n, "/bar/foo/baz", NULL); -r3_tree_insert_path(n, "/bar/foo/qux", NULL); -r3_tree_insert_path(n, "/bar/foo/quux", NULL); -r3_tree_insert_path(n, "/bar/foo/corge", NULL); -r3_tree_insert_path(n, "/bar/foo/grault", NULL); -r3_tree_insert_path(n, "/bar/foo/garply", NULL); -r3_tree_insert_path(n, "/bar/baz/foo", NULL); -r3_tree_insert_path(n, "/bar/baz/qux", NULL); -r3_tree_insert_path(n, "/bar/baz/quux", NULL); -r3_tree_insert_path(n, "/bar/baz/corge", NULL); -r3_tree_insert_path(n, "/bar/baz/grault", NULL); -r3_tree_insert_path(n, "/bar/baz/garply", NULL); -r3_tree_insert_path(n, "/bar/qux/foo", NULL); -r3_tree_insert_path(n, "/bar/qux/baz", NULL); -r3_tree_insert_path(n, "/bar/qux/quux", NULL); -r3_tree_insert_path(n, "/bar/qux/corge", NULL); -r3_tree_insert_path(n, "/bar/qux/grault", NULL); -r3_tree_insert_path(n, "/bar/qux/garply", NULL); -r3_tree_insert_path(n, "/bar/quux/foo", NULL); -r3_tree_insert_path(n, "/bar/quux/baz", NULL); -r3_tree_insert_path(n, "/bar/quux/qux", NULL); -r3_tree_insert_path(n, "/bar/quux/corge", NULL); -r3_tree_insert_path(n, "/bar/quux/grault", NULL); -r3_tree_insert_path(n, "/bar/quux/garply", NULL); -r3_tree_insert_path(n, "/bar/corge/foo", NULL); -r3_tree_insert_path(n, "/bar/corge/baz", NULL); -r3_tree_insert_path(n, "/bar/corge/qux", NULL); -r3_tree_insert_path(n, "/bar/corge/quux", NULL); -r3_tree_insert_path(n, "/bar/corge/grault", NULL); -r3_tree_insert_path(n, "/bar/corge/garply", NULL); -r3_tree_insert_path(n, "/bar/grault/foo", NULL); -r3_tree_insert_path(n, "/bar/grault/baz", NULL); -r3_tree_insert_path(n, "/bar/grault/qux", NULL); -r3_tree_insert_path(n, "/bar/grault/quux", NULL); -r3_tree_insert_path(n, "/bar/grault/corge", NULL); -r3_tree_insert_path(n, "/bar/grault/garply", NULL); -r3_tree_insert_path(n, "/bar/garply/foo", NULL); -r3_tree_insert_path(n, "/bar/garply/baz", NULL); -r3_tree_insert_path(n, "/bar/garply/qux", NULL); -r3_tree_insert_path(n, "/bar/garply/quux", NULL); -r3_tree_insert_path(n, "/bar/garply/corge", NULL); -r3_tree_insert_path(n, "/bar/garply/grault", NULL); -r3_tree_insert_path(n, "/baz/foo/bar", NULL); -r3_tree_insert_path(n, "/baz/foo/qux", NULL); -r3_tree_insert_path(n, "/baz/foo/quux", NULL); -r3_tree_insert_path(n, "/baz/foo/corge", NULL); -r3_tree_insert_path(n, "/baz/foo/grault", NULL); -r3_tree_insert_path(n, "/baz/foo/garply", NULL); -r3_tree_insert_path(n, "/baz/bar/foo", NULL); -r3_tree_insert_path(n, "/baz/bar/qux", NULL); -r3_tree_insert_path(n, "/baz/bar/quux", NULL); -r3_tree_insert_path(n, "/baz/bar/corge", NULL); -r3_tree_insert_path(n, "/baz/bar/grault", NULL); -r3_tree_insert_path(n, "/baz/bar/garply", NULL); -r3_tree_insert_path(n, "/baz/qux/foo", NULL); -r3_tree_insert_path(n, "/baz/qux/bar", NULL); -r3_tree_insert_path(n, "/baz/qux/quux", NULL); -r3_tree_insert_path(n, "/baz/qux/corge", NULL); -r3_tree_insert_path(n, "/baz/qux/grault", NULL); -r3_tree_insert_path(n, "/baz/qux/garply", NULL); -r3_tree_insert_path(n, "/baz/quux/foo", NULL); -r3_tree_insert_path(n, "/baz/quux/bar", NULL); -r3_tree_insert_path(n, "/baz/quux/qux", NULL); -r3_tree_insert_path(n, "/baz/quux/corge", NULL); -r3_tree_insert_path(n, "/baz/quux/grault", NULL); -r3_tree_insert_path(n, "/baz/quux/garply", NULL); -r3_tree_insert_path(n, "/baz/corge/foo", NULL); -r3_tree_insert_path(n, "/baz/corge/bar", NULL); -r3_tree_insert_path(n, "/baz/corge/qux", NULL); -r3_tree_insert_path(n, "/baz/corge/quux", NULL); -r3_tree_insert_path(n, "/baz/corge/grault", NULL); -r3_tree_insert_path(n, "/baz/corge/garply", NULL); -r3_tree_insert_path(n, "/baz/grault/foo", NULL); -r3_tree_insert_path(n, "/baz/grault/bar", NULL); -r3_tree_insert_path(n, "/baz/grault/qux", NULL); -r3_tree_insert_path(n, "/baz/grault/quux", NULL); -r3_tree_insert_path(n, "/baz/grault/corge", NULL); -r3_tree_insert_path(n, "/baz/grault/garply", NULL); -r3_tree_insert_path(n, "/baz/garply/foo", NULL); -r3_tree_insert_path(n, "/baz/garply/bar", NULL); -r3_tree_insert_path(n, "/baz/garply/qux", NULL); -r3_tree_insert_path(n, "/baz/garply/quux", NULL); -r3_tree_insert_path(n, "/baz/garply/corge", NULL); -r3_tree_insert_path(n, "/baz/garply/grault", NULL); -r3_tree_insert_path(n, "/qux/foo/bar", NULL); -r3_tree_insert_path(n, "/qux/foo/baz", NULL); -r3_tree_insert_path(n, "/qux/foo/quux", NULL); -r3_tree_insert_path(n, "/qux/foo/corge", NULL); -r3_tree_insert_path(n, "/qux/foo/grault", NULL); -r3_tree_insert_path(n, "/qux/foo/garply", NULL); -r3_tree_insert_path(n, "/qux/bar/foo", NULL); -r3_tree_insert_path(n, "/qux/bar/baz", NULL); -r3_tree_insert_path(n, "/qux/bar/quux", NULL); -r3_tree_insert_path(n, "/qux/bar/corge", &route_data); -r3_tree_insert_path(n, "/qux/bar/grault", NULL); -r3_tree_insert_path(n, "/qux/bar/garply", NULL); -r3_tree_insert_path(n, "/qux/baz/foo", NULL); -r3_tree_insert_path(n, "/qux/baz/bar", NULL); -r3_tree_insert_path(n, "/qux/baz/quux", NULL); -r3_tree_insert_path(n, "/qux/baz/corge", NULL); -r3_tree_insert_path(n, "/qux/baz/grault", NULL); -r3_tree_insert_path(n, "/qux/baz/garply", NULL); -r3_tree_insert_path(n, "/qux/quux/foo", NULL); -r3_tree_insert_path(n, "/qux/quux/bar", NULL); -r3_tree_insert_path(n, "/qux/quux/baz", NULL); -r3_tree_insert_path(n, "/qux/quux/corge", NULL); -r3_tree_insert_path(n, "/qux/quux/grault", NULL); -r3_tree_insert_path(n, "/qux/quux/garply", NULL); -r3_tree_insert_path(n, "/qux/corge/foo", NULL); -r3_tree_insert_path(n, "/qux/corge/bar", NULL); -r3_tree_insert_path(n, "/qux/corge/baz", NULL); -r3_tree_insert_path(n, "/qux/corge/quux", NULL); -r3_tree_insert_path(n, "/qux/corge/grault", NULL); -r3_tree_insert_path(n, "/qux/corge/garply", NULL); -r3_tree_insert_path(n, "/qux/grault/foo", NULL); -r3_tree_insert_path(n, "/qux/grault/bar", NULL); -r3_tree_insert_path(n, "/qux/grault/baz", NULL); -r3_tree_insert_path(n, "/qux/grault/quux", NULL); -r3_tree_insert_path(n, "/qux/grault/corge", NULL); -r3_tree_insert_path(n, "/qux/grault/garply", NULL); -r3_tree_insert_path(n, "/qux/garply/foo", NULL); -r3_tree_insert_path(n, "/qux/garply/bar", NULL); -r3_tree_insert_path(n, "/qux/garply/baz", NULL); -r3_tree_insert_path(n, "/qux/garply/quux", NULL); -r3_tree_insert_path(n, "/qux/garply/corge", NULL); -r3_tree_insert_path(n, "/qux/garply/grault", NULL); -r3_tree_insert_path(n, "/quux/foo/bar", NULL); -r3_tree_insert_path(n, "/quux/foo/baz", NULL); -r3_tree_insert_path(n, "/quux/foo/qux", NULL); -r3_tree_insert_path(n, "/quux/foo/corge", NULL); -r3_tree_insert_path(n, "/quux/foo/grault", NULL); -r3_tree_insert_path(n, "/quux/foo/garply", NULL); -r3_tree_insert_path(n, "/quux/bar/foo", NULL); -r3_tree_insert_path(n, "/quux/bar/baz", NULL); -r3_tree_insert_path(n, "/quux/bar/qux", NULL); -r3_tree_insert_path(n, "/quux/bar/corge", NULL); -r3_tree_insert_path(n, "/quux/bar/grault", NULL); -r3_tree_insert_path(n, "/quux/bar/garply", NULL); -r3_tree_insert_path(n, "/quux/baz/foo", NULL); -r3_tree_insert_path(n, "/quux/baz/bar", NULL); -r3_tree_insert_path(n, "/quux/baz/qux", NULL); -r3_tree_insert_path(n, "/quux/baz/corge", NULL); -r3_tree_insert_path(n, "/quux/baz/grault", NULL); -r3_tree_insert_path(n, "/quux/baz/garply", NULL); -r3_tree_insert_path(n, "/quux/qux/foo", NULL); -r3_tree_insert_path(n, "/quux/qux/bar", NULL); -r3_tree_insert_path(n, "/quux/qux/baz", NULL); -r3_tree_insert_path(n, "/quux/qux/corge", NULL); -r3_tree_insert_path(n, "/quux/qux/grault", NULL); -r3_tree_insert_path(n, "/quux/qux/garply", NULL); -r3_tree_insert_path(n, "/quux/corge/foo", NULL); -r3_tree_insert_path(n, "/quux/corge/bar", NULL); -r3_tree_insert_path(n, "/quux/corge/baz", NULL); -r3_tree_insert_path(n, "/quux/corge/qux", NULL); -r3_tree_insert_path(n, "/quux/corge/grault", NULL); -r3_tree_insert_path(n, "/quux/corge/garply", NULL); -r3_tree_insert_path(n, "/quux/grault/foo", NULL); -r3_tree_insert_path(n, "/quux/grault/bar", NULL); -r3_tree_insert_path(n, "/quux/grault/baz", NULL); -r3_tree_insert_path(n, "/quux/grault/qux", NULL); -r3_tree_insert_path(n, "/quux/grault/corge", NULL); -r3_tree_insert_path(n, "/quux/grault/garply", NULL); -r3_tree_insert_path(n, "/quux/garply/foo", NULL); -r3_tree_insert_path(n, "/quux/garply/bar", NULL); -r3_tree_insert_path(n, "/quux/garply/baz", NULL); -r3_tree_insert_path(n, "/quux/garply/qux", NULL); -r3_tree_insert_path(n, "/quux/garply/corge", NULL); -r3_tree_insert_path(n, "/quux/garply/grault", NULL); -r3_tree_insert_path(n, "/corge/foo/bar", NULL); -r3_tree_insert_path(n, "/corge/foo/baz", NULL); -r3_tree_insert_path(n, "/corge/foo/qux", NULL); -r3_tree_insert_path(n, "/corge/foo/quux", NULL); -r3_tree_insert_path(n, "/corge/foo/grault", NULL); -r3_tree_insert_path(n, "/corge/foo/garply", NULL); -r3_tree_insert_path(n, "/corge/bar/foo", NULL); -r3_tree_insert_path(n, "/corge/bar/baz", NULL); -r3_tree_insert_path(n, "/corge/bar/qux", NULL); -r3_tree_insert_path(n, "/corge/bar/quux", NULL); -r3_tree_insert_path(n, "/corge/bar/grault", NULL); -r3_tree_insert_path(n, "/corge/bar/garply", NULL); -r3_tree_insert_path(n, "/corge/baz/foo", NULL); -r3_tree_insert_path(n, "/corge/baz/bar", NULL); -r3_tree_insert_path(n, "/corge/baz/qux", NULL); -r3_tree_insert_path(n, "/corge/baz/quux", NULL); -r3_tree_insert_path(n, "/corge/baz/grault", NULL); -r3_tree_insert_path(n, "/corge/baz/garply", NULL); -r3_tree_insert_path(n, "/corge/qux/foo", NULL); -r3_tree_insert_path(n, "/corge/qux/bar", NULL); -r3_tree_insert_path(n, "/corge/qux/baz", NULL); -r3_tree_insert_path(n, "/corge/qux/quux", NULL); -r3_tree_insert_path(n, "/corge/qux/grault", NULL); -r3_tree_insert_path(n, "/corge/qux/garply", NULL); -r3_tree_insert_path(n, "/corge/quux/foo", NULL); -r3_tree_insert_path(n, "/corge/quux/bar", NULL); -r3_tree_insert_path(n, "/corge/quux/baz", NULL); -r3_tree_insert_path(n, "/corge/quux/qux", NULL); -r3_tree_insert_path(n, "/corge/quux/grault", NULL); -r3_tree_insert_path(n, "/corge/quux/garply", NULL); -r3_tree_insert_path(n, "/corge/grault/foo", NULL); -r3_tree_insert_path(n, "/corge/grault/bar", NULL); -r3_tree_insert_path(n, "/corge/grault/baz", NULL); -r3_tree_insert_path(n, "/corge/grault/qux", NULL); -r3_tree_insert_path(n, "/corge/grault/quux", NULL); -r3_tree_insert_path(n, "/corge/grault/garply", NULL); -r3_tree_insert_path(n, "/corge/garply/foo", NULL); -r3_tree_insert_path(n, "/corge/garply/bar", NULL); -r3_tree_insert_path(n, "/corge/garply/baz", NULL); -r3_tree_insert_path(n, "/corge/garply/qux", NULL); -r3_tree_insert_path(n, "/corge/garply/quux", NULL); -r3_tree_insert_path(n, "/corge/garply/grault", NULL); -r3_tree_insert_path(n, "/grault/foo/bar", NULL); -r3_tree_insert_path(n, "/grault/foo/baz", NULL); -r3_tree_insert_path(n, "/grault/foo/qux", NULL); -r3_tree_insert_path(n, "/grault/foo/quux", NULL); -r3_tree_insert_path(n, "/grault/foo/corge", NULL); -r3_tree_insert_path(n, "/grault/foo/garply", NULL); -r3_tree_insert_path(n, "/grault/bar/foo", NULL); -r3_tree_insert_path(n, "/grault/bar/baz", NULL); -r3_tree_insert_path(n, "/grault/bar/qux", NULL); -r3_tree_insert_path(n, "/grault/bar/quux", NULL); -r3_tree_insert_path(n, "/grault/bar/corge", NULL); -r3_tree_insert_path(n, "/grault/bar/garply", NULL); -r3_tree_insert_path(n, "/grault/baz/foo", NULL); -r3_tree_insert_path(n, "/grault/baz/bar", NULL); -r3_tree_insert_path(n, "/grault/baz/qux", NULL); -r3_tree_insert_path(n, "/grault/baz/quux", NULL); -r3_tree_insert_path(n, "/grault/baz/corge", NULL); -r3_tree_insert_path(n, "/grault/baz/garply", NULL); -r3_tree_insert_path(n, "/grault/qux/foo", NULL); -r3_tree_insert_path(n, "/grault/qux/bar", NULL); -r3_tree_insert_path(n, "/grault/qux/baz", NULL); -r3_tree_insert_path(n, "/grault/qux/quux", NULL); -r3_tree_insert_path(n, "/grault/qux/corge", NULL); -r3_tree_insert_path(n, "/grault/qux/garply", NULL); -r3_tree_insert_path(n, "/grault/quux/foo", NULL); -r3_tree_insert_path(n, "/grault/quux/bar", NULL); -r3_tree_insert_path(n, "/grault/quux/baz", NULL); -r3_tree_insert_path(n, "/grault/quux/qux", NULL); -r3_tree_insert_path(n, "/grault/quux/corge", NULL); -r3_tree_insert_path(n, "/grault/quux/garply", NULL); -r3_tree_insert_path(n, "/grault/corge/foo", NULL); -r3_tree_insert_path(n, "/grault/corge/bar", NULL); -r3_tree_insert_path(n, "/grault/corge/baz", NULL); -r3_tree_insert_path(n, "/grault/corge/qux", NULL); -r3_tree_insert_path(n, "/grault/corge/quux", NULL); -r3_tree_insert_path(n, "/grault/corge/garply", NULL); -r3_tree_insert_path(n, "/grault/garply/foo", NULL); -r3_tree_insert_path(n, "/grault/garply/bar", NULL); -r3_tree_insert_path(n, "/grault/garply/baz", NULL); -r3_tree_insert_path(n, "/grault/garply/qux", NULL); -r3_tree_insert_path(n, "/grault/garply/quux", NULL); -r3_tree_insert_path(n, "/grault/garply/corge", NULL); -r3_tree_insert_path(n, "/garply/foo/bar", NULL); -r3_tree_insert_path(n, "/garply/foo/baz", NULL); -r3_tree_insert_path(n, "/garply/foo/qux", NULL); -r3_tree_insert_path(n, "/garply/foo/quux", NULL); -r3_tree_insert_path(n, "/garply/foo/corge", NULL); -r3_tree_insert_path(n, "/garply/foo/grault", NULL); -r3_tree_insert_path(n, "/garply/bar/foo", NULL); -r3_tree_insert_path(n, "/garply/bar/baz", NULL); -r3_tree_insert_path(n, "/garply/bar/qux", NULL); -r3_tree_insert_path(n, "/garply/bar/quux", NULL); -r3_tree_insert_path(n, "/garply/bar/corge", NULL); -r3_tree_insert_path(n, "/garply/bar/grault", NULL); -r3_tree_insert_path(n, "/garply/baz/foo", NULL); -r3_tree_insert_path(n, "/garply/baz/bar", NULL); -r3_tree_insert_path(n, "/garply/baz/qux", NULL); -r3_tree_insert_path(n, "/garply/baz/quux", NULL); -r3_tree_insert_path(n, "/garply/baz/corge", NULL); -r3_tree_insert_path(n, "/garply/baz/grault", NULL); -r3_tree_insert_path(n, "/garply/qux/foo", NULL); -r3_tree_insert_path(n, "/garply/qux/bar", NULL); -r3_tree_insert_path(n, "/garply/qux/baz", NULL); -r3_tree_insert_path(n, "/garply/qux/quux", NULL); -r3_tree_insert_path(n, "/garply/qux/corge", NULL); -r3_tree_insert_path(n, "/garply/qux/grault", NULL); -r3_tree_insert_path(n, "/garply/quux/foo", NULL); -r3_tree_insert_path(n, "/garply/quux/bar", NULL); -r3_tree_insert_path(n, "/garply/quux/baz", NULL); -r3_tree_insert_path(n, "/garply/quux/qux", NULL); -r3_tree_insert_path(n, "/garply/quux/corge", NULL); -r3_tree_insert_path(n, "/garply/quux/grault", NULL); -r3_tree_insert_path(n, "/garply/corge/foo", NULL); -r3_tree_insert_path(n, "/garply/corge/bar", NULL); -r3_tree_insert_path(n, "/garply/corge/baz", NULL); -r3_tree_insert_path(n, "/garply/corge/qux", NULL); -r3_tree_insert_path(n, "/garply/corge/quux", NULL); -r3_tree_insert_path(n, "/garply/corge/grault", NULL); -r3_tree_insert_path(n, "/garply/grault/foo", NULL); -r3_tree_insert_path(n, "/garply/grault/bar", NULL); -r3_tree_insert_path(n, "/garply/grault/baz", NULL); -r3_tree_insert_path(n, "/garply/grault/qux", NULL); -r3_tree_insert_path(n, "/garply/grault/quux", NULL); -r3_tree_insert_path(n, "/garply/grault/corge", NULL); - - BENCHMARK(tree_compile) - r3_tree_compile(n); - END_BENCHMARK(tree_compile) - - node *m; - m = r3_tree_match(n , "/qux/bar/corge", NULL); - ck_assert(m != NULL); - ck_assert_int_eq( *((int*) m->data), 999 ); - - - BENCHMARK(string_dispatch) - r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL); - END_BENCHMARK(string_dispatch) - BENCHMARK_SUMMARY(string_dispatch); - - - node * tree2 = r3_tree_create(1); - r3_tree_insert_path(tree2, "/post/{year}/{month}", NULL); - r3_tree_compile(tree2); - - BENCHMARK(pcre_dispatch) - r3_tree_matchl(tree2, "/post/2014/12", strlen("/post/2014/12"), NULL); - END_BENCHMARK(pcre_dispatch) - BENCHMARK_SUMMARY(pcre_dispatch); - - - BENCHMARK_RECORD_CSV("bench_str.csv", 2, BR(string_dispatch), BR(pcre_dispatch), BR(tree_compile) ); -} -END_TEST - - Suite* r3_suite (void) { Suite *suite = suite_create("blah"); @@ -751,7 +376,6 @@ Suite* r3_suite (void) { tcase_add_test(tcase, test_pcre_patterns_insert); tcase_add_test(tcase, test_pcre_patterns_insert_2); tcase_add_test(tcase, test_pcre_patterns_insert_3); - tcase_add_test(tcase, benchmark_str); tcase_set_timeout(tcase, 30); suite_add_tcase(suite, tcase); From 5d82ae0f8276b0593fb250d2e0ece33ebd6eb6ee Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 21:57:33 +0800 Subject: [PATCH 14/19] Fix benchmark rendering --- bench.html | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bench.html b/bench.html index 7c44179..c0a3de5 100644 --- a/bench.html +++ b/bench.html @@ -139,15 +139,14 @@ $(lines).each(function(i,line) { var columns = line.split(/,/); var a; - if (a = parseInt(columns[1])) { - options.series[0].data.push(a || 0); - } - if (a = parseInt(columns[2])) { - options.series[1].data.push(a || 0); - } - if (a = parseInt(columns[3])) { - options.series[2].data.push(a || 0); - } + a = parseInt(columns[1]); + options.series[0].data.push(a || 0); + + a = parseInt(columns[2]); + options.series[1].data.push(a || 0); + + a = parseInt(columns[3]); + options.series[2].data.push(a || 0); }); $('#chart').highcharts(options); From fef3361ed2085f88140671678608030d80b23d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChangZhuo=20Chen=20=28=E9=99=B3=E6=98=8C=E5=80=AC=29?= Date: Thu, 22 May 2014 22:06:11 +0800 Subject: [PATCH 15/19] Set test timeout to 30 --- tests/check_slug.c | 1 + tests/check_tree.c | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/check_slug.c b/tests/check_slug.c index 88b11e6..06567b7 100644 --- a/tests/check_slug.c +++ b/tests/check_slug.c @@ -97,6 +97,7 @@ END_TEST Suite* r3_suite (void) { Suite *suite = suite_create("slug test"); TCase *tcase = tcase_create("test_slug"); + tcase_set_timeout(tcase, 30); tcase_add_test(tcase, test_contains_slug); tcase_add_test(tcase, test_inside_slug); tcase_add_test(tcase, test_find_slug_pattern); diff --git a/tests/check_tree.c b/tests/check_tree.c index 72af3e1..ee2370d 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -736,6 +736,7 @@ Suite* r3_suite (void) { Suite *suite = suite_create("blah"); TCase *tcase = tcase_create("testcase"); + tcase_set_timeout(tcase, 30); tcase_add_test(tcase, test_r3_node_construct_and_free); tcase_add_test(tcase, test_str_array); tcase_add_test(tcase, test_ltrim_slash); From 5a10c82ea5020a1b54cd1719fe5b420008050d82 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 22:21:29 +0800 Subject: [PATCH 16/19] R3_NODE_H as the include guard --- include/r3.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/r3.h b/include/r3.h index e4583f3..959aff6 100644 --- a/include/r3.h +++ b/include/r3.h @@ -4,9 +4,8 @@ * * Distributed under terms of the MIT license. */ - -#ifndef NODE_H -#define NODE_H +#ifndef R3_NODE_H +#define R3_NODE_H #include #include @@ -172,4 +171,4 @@ route * r3_tree_match_route(const node *n, match_entry * entry); #define METHOD_PUT 2<<1 #define METHOD_DELETE 2<<1 -#endif /* !NODE_H */ +#endif /* !R3_NODE_H */ From 288cdc91dd0077674229b170f30498a84adb2958 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 22:22:03 +0800 Subject: [PATCH 17/19] R3_LIST_H --- config.h | 6 +++--- include/r3_list.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config.h b/config.h index eae0dba..430376f 100644 --- a/config.h +++ b/config.h @@ -2,7 +2,7 @@ /* config.h.in. Generated from configure.ac by autoheader. */ /* "whether graphviz is enable" */ -#define ENABLE_GRAPHVIZ test "x$enable_graphviz" == "xyes" +#define ENABLE_GRAPHVIZ test "x$enable_graphviz" = "xyes" /* Define to 1 if you have the header file. */ #define HAVE_DLFCN_H 1 @@ -94,8 +94,8 @@ /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 -/* "use jemalloc" */ -#define USE_JEMALLOC test "x$found_jemalloc" = "xyes" +/* Define to 1 if you have the PATH_MAX macro. */ +/* #undef USE_JEMALLOC */ /* Version number of package */ #define VERSION "1.0.0" diff --git a/include/r3_list.h b/include/r3_list.h index 96e878c..bd231ef 100644 --- a/include/r3_list.h +++ b/include/r3_list.h @@ -5,8 +5,8 @@ * Distributed under terms of the MIT license. */ -#ifndef LIST_H -#define LIST_H +#ifndef R3_LIST_H +#define R3_LIST_H #include @@ -32,4 +32,4 @@ void list_each_element(list *l, int (*func)(list_item *)); -#endif /* !LIST_H */ +#endif /* !R3_LIST_H */ From fe5c2381b53b18a3425547f504ac96ea551cba58 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 22:23:47 +0800 Subject: [PATCH 18/19] remove point checking in str_array_free --- src/token.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/token.c b/src/token.c index 5c00e2e..e0f23a8 100644 --- a/src/token.c +++ b/src/token.c @@ -23,9 +23,7 @@ str_array * str_array_create(int cap) { void str_array_free(str_array *l) { for ( int i = 0; i < l->len ; i++ ) { char * t = l->tokens[ i ]; - if (t) { - zfree(t); - } + zfree(t); } zfree(l); } From 62bb4e5460c7a33fc5e8fbcb8d0ce0bdbc26e9ab Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 22:26:14 +0800 Subject: [PATCH 19/19] remove unnecessary pointer check --- src/node.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/node.c b/src/node.c index 302c20e..671974b 100644 --- a/src/node.c +++ b/src/node.c @@ -246,10 +246,8 @@ match_entry * match_entry_createl(char * path, int path_len) { } void match_entry_free(match_entry * entry) { - if (entry) { - str_array_free(entry->vars); - zfree(entry); - } + str_array_free(entry->vars); + zfree(entry); } @@ -396,9 +394,7 @@ route * r3_route_create(char * path) { } void r3_route_free(route * route) { - if (route) { - zfree(route); - } + zfree(route); } route * r3_route_createl(char * path, int path_len) {