From 992bb6a73aae22c1c636eac9cb72aa2e47478a93 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 4 Mar 2018 01:16:37 +0100 Subject: [PATCH] Add bench of hash computation library (XXHASH) --- bench/Makefile | 8 ++++++++ bench/bench-xxhash.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 bench/bench-xxhash.c diff --git a/bench/Makefile b/bench/Makefile index 34280856..a2afeda7 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -238,6 +238,14 @@ bench-concurrentqueue0: @./bench-concurrentqueue.exe 60 +# XXHASH shall point to the source directory of xxhash +bench-xxhash: + @if test -n "$${XXHASH}" ; then $(MAKE) bench-xxhash0 ; else echo "Nothing to be done for XXHASH." ; fi + +bench-xxhash0: + $(CC) $(CFLAGS) $(CPPFLAGS) -I "$${XXHASH}/" bench-xxhash.c "$${XXHASH}/libxxhash.a" -o bench-xxhash.exe + @./bench-xxhash.exe 70 + # BOOST is assumed to be installed in the system bench-boost: $(CXX) $(CFLAGS) $(CPPFLAGS) bench-boost.cpp -o bench-boost.exe -lpthread diff --git a/bench/bench-xxhash.c b/bench/bench-xxhash.c new file mode 100644 index 00000000..a571e913 --- /dev/null +++ b/bench/bench-xxhash.c @@ -0,0 +1,47 @@ +#define NDEBUG + +#include +#include +#include + +#include "xxhash.h" + +#include "common.h" + +static unsigned long *g_p; + +static void test_hash_prepare(size_t n) +{ + g_p = malloc (n * sizeof(unsigned long)); + if (g_p == NULL) abort(); + for(size_t i = 0; i < n ; i++) + g_p[i] = ((rand_get()*RAND_MAX + rand_get())*RAND_MAX+rand_get())*RAND_MAX + rand_get(); +} + + +static void test_hash_final(void) +{ + free(g_p); +} + +static void test_hash(size_t n) +{ + g_result = XXH64(g_p, sizeof(unsigned long)*n, 0); +} + +/********************************************************************************************/ + + +int main(int argc, const char *argv[]) +{ + int n = (argc > 1) ? atoi(argv[1]) : 0; + if (n == 70) { + n = (argc > 2) ? atoi(argv[2]) : 100000000; + test_hash_prepare(n); + test_function("XXHASH64 time", n, test_hash); + test_hash_final(); + } + + exit(0); +} +