Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Scott
committed
Apr 29, 2011
1 parent
9a0d23c
commit 3fa6f74
Showing
4 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Benchmarking code. */ | ||
|
||
#include "yatrie.h" | ||
#include "benchmark.h" | ||
|
||
void run_benchmarks(void) { | ||
int asizes[] = {2, 5, 10, 30, 500}; | ||
int i, j; | ||
yatrie_t trie = (yatrie_t)NULL; | ||
int set_time = 0; int get_time = 0; | ||
|
||
BENCHMARK_INIT(); | ||
|
||
for (i = 0; i < 5; i++) { | ||
int array_size = asizes[i]; | ||
|
||
/* Contiguous keys */ | ||
TICK(); | ||
for (j = 0; j < array_size; j++) | ||
trie = yatrie_insert(trie, j, j); | ||
TOCK(); | ||
set_time += benchmark_total_time * 500 / array_size; | ||
|
||
TICK(); | ||
for (j = 0; j < array_size; j++) | ||
yatrie_get(trie, j); | ||
TOCK(); | ||
get_time += benchmark_total_time * 500 / array_size; | ||
yatrie_free(trie); trie = (yatrie_t)NULL; | ||
|
||
/* Uniform keys */ | ||
srand(1234567); | ||
TICK(); | ||
for (j = 0; j < array_size; j++) | ||
trie = yatrie_insert(trie, rand(), j); | ||
TOCK(); | ||
set_time += benchmark_total_time * 500 / array_size; | ||
|
||
TICK(); | ||
for (j = 0; j < array_size; j++) | ||
yatrie_get(trie, rand()); | ||
TOCK(); | ||
get_time += benchmark_total_time * 500 / array_size; | ||
yatrie_free(trie); trie = (yatrie_t)NULL; | ||
} | ||
|
||
printf("%i %i\n", get_time, set_time); | ||
} | ||
|
||
int main(void) { | ||
run_benchmarks(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Really simple benchmarking tool. Surround sections of code to benchmark with | ||
TICK(); ... TOCK(); and look at the benchmark_total_time variable to get the | ||
total number of microseconds elapsed between TICK and TOCK calls. You must | ||
call BENCHMARK_INIT() at the beginning of your program. */ | ||
#ifndef __BENCHMARK_H | ||
#define __BENCHMARK_H | ||
|
||
#include <time.h> | ||
|
||
static clock_t __benchmark_h_time; | ||
static int benchmark_total_time = 0; | ||
|
||
#define BENCHMARK_INIT() benchmark_total_time = 0; | ||
#define TICK() __benchmark_h_time = clock(); | ||
#define TOCK() benchmark_total_time += clock() - __benchmark_h_time; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
CFLAGS = -g -Wall | ||
HEADERS = yatrie.h config.h params.h | ||
all: sttest ttest bigtest | ||
all: sttest ttest bigtest benchmark | ||
|
||
sttest: sttest.o simpletrie.o $(HEADERS) | ||
ttest: sttest.o trie.o $(HEADERS) | ||
gcc $^ -o $@ | ||
bigtest: bigtest.o trie.o $(HEADERS) | ||
benchmark: benchmark.o trie.o $(HEADERS) | ||
bmsimple: benchmark.o simpletrie.o $(HEADERS) | ||
|
||
clean: | ||
rm -f *.o sttest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters