From: vivek Date: Tue, 28 Apr 2015 21:29:18 +0000 (+0200) Subject: eina: add benchmark for crc hash in eina benchmark X-Git-Tag: v1.15.0-alpha1~695 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eec4a7bd0caa7d52bff6cc524ca12efa16d1445b;p=platform%2Fupstream%2Fefl.git eina: add benchmark for crc hash in eina benchmark Summary: The code added is actually benchmarking all hash function key with various length (8, 32, 256 bytes). Signed-off-by: vivek Reviewers: Sergeant_Whitespace, cedric Reviewed By: cedric Subscribers: Sergeant_Whitespace, cedric Differential Revision: https://phab.enlightenment.org/D2217 Signed-off-by: Cedric BAIL --- diff --git a/src/benchmarks/eina/Makefile.am b/src/benchmarks/eina/Makefile.am index 9f64d46..da6ceb9 100644 --- a/src/benchmarks/eina/Makefile.am +++ b/src/benchmarks/eina/Makefile.am @@ -18,6 +18,7 @@ eina_bench_SOURCES = \ eina_bench.c \ eina_bench_sort.c \ eina_bench_hash.c \ +eina_bench_crc_hash.c \ eina_bench_stringshare.c \ eina_bench_convert.c \ eina_bench_mempool.c \ diff --git a/src/benchmarks/eina/eina_bench.c b/src/benchmarks/eina/eina_bench.c index dec210e..1ca7e51 100644 --- a/src/benchmarks/eina/eina_bench.c +++ b/src/benchmarks/eina/eina_bench.c @@ -37,6 +37,9 @@ struct _Eina_Benchmark_Case static const Eina_Benchmark_Case etc[] = { { "Hash", eina_bench_hash, EINA_TRUE }, + { "Hash_Short_Key", eina_bench_crc_hash_short, EINA_TRUE }, + { "Hash_Medium_Key", eina_bench_crc_hash_medium, EINA_TRUE }, + { "Hash_Large_key", eina_bench_crc_hash_large, EINA_TRUE }, { "Array vs List vs Inlist", eina_bench_array, EINA_TRUE }, { "Stringshare", eina_bench_stringshare, EINA_TRUE }, { "Convert", eina_bench_convert, EINA_TRUE }, diff --git a/src/benchmarks/eina/eina_bench.h b/src/benchmarks/eina/eina_bench.h index d575822..f076d41 100644 --- a/src/benchmarks/eina/eina_bench.h +++ b/src/benchmarks/eina/eina_bench.h @@ -21,7 +21,12 @@ #include "eina_benchmark.h" +int key_size; + void eina_bench_hash(Eina_Benchmark *bench); +void eina_bench_crc_hash_short(Eina_Benchmark *bench); +void eina_bench_crc_hash_medium(Eina_Benchmark *bench); +void eina_bench_crc_hash_large(Eina_Benchmark *bench); void eina_bench_array(Eina_Benchmark *bench); void eina_bench_stringshare(Eina_Benchmark *bench); void eina_bench_convert(Eina_Benchmark *bench); diff --git a/src/benchmarks/eina/eina_bench_crc_hash.c b/src/benchmarks/eina/eina_bench_crc_hash.c new file mode 100644 index 0000000..b673448 --- /dev/null +++ b/src/benchmarks/eina/eina_bench_crc_hash.c @@ -0,0 +1,279 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include + +#ifdef EINA_BENCH_HAVE_GLIB +# include +#endif + +#include +#include "Evas_Data.h" +#include "Ecore_Data.h" + +#include "eina_hash.h" +#include "eina_array.h" +#include "eina_bench.h" +#include "eina_rbtree.h" +#include "eina_convert.h" + +#ifdef CITYHASH_BENCH +// Hash function for a byte array. +uint64_t CityHash64(const char *buf, size_t len); +#endif + +char *key_str=NULL; + +void repchar(int n) +{ + key_str = (char *)malloc(n); + int i; + + for (i = 0; i < n; i++) + key_str[i] = 'a'; +} + +static void +eina_bench_murmur_hash(int request) +{ + unsigned int i; + + for (i = 0; i < (unsigned int)request; ++i) + { + char tmp_key[key_size]; + + eina_convert_itoa(i, tmp_key); + eina_strlcat(tmp_key, key_str, key_size); + + eina_hash_murmur3(tmp_key, key_size); + } +} + +#ifdef CITYHASH_BENCH +static void +eina_bench_cityhash(int request) +{ + unsigned int i; + + for (i = 0; i < (unsigned int)request; ++i) + { + char tmp_key[key_size]; + + eina_convert_itoa(i, tmp_key); + eina_strlcat(tmp_key, key_str, key_size); + + CityHash64(tmp_key, key_size); + } +} +#endif + +static void +eina_bench_superfast_hash(int request) +{ + unsigned int i; + + for (i = 0; i < (unsigned int)request; ++i) + { + char tmp_key[key_size]; + + eina_convert_itoa(i, tmp_key); + eina_strlcat(tmp_key, key_str, key_size); + + eina_hash_superfast(tmp_key, key_size); + } +} + +static void +eina_bench_crchash(int request) +{ + unsigned int i; + + for (i = 0; i < (unsigned int)request; ++i) + { + char tmp_key[key_size]; + + eina_convert_itoa(i, tmp_key); + eina_strlcat(tmp_key, key_str, key_size); + + eina_hash_crc(tmp_key, key_size); + } +} + +static void +eina_bench_djb2_hash(int request) +{ + unsigned int i; + + for (i = 0; i < (unsigned int)request; ++i) + { + char tmp_key[key_size]; + + eina_convert_itoa(i, tmp_key); + eina_strlcat(tmp_key, key_str, key_size); + + eina_hash_djb2(tmp_key, key_size); + } +} + +#ifdef EINA_BENCH_HAVE_GLIB +static void +eina_bench_ghash(int request) +{ + unsigned int i; + + for (i = 0; i < (unsigned int)request; ++i) + { + char tmp_key[key_size]; + + eina_convert_itoa(i, tmp_key); + eina_strlcat(tmp_key, key_str, key_size); + + g_str_hash(key_str); + } +} +#endif + +int +evas_hash_gen(const char *key) +{ + unsigned int hash_num = 5381; + const unsigned char *ptr; + + if (!key) + return 0; + + for (ptr = (unsigned char *)key; *ptr; ptr++) + hash_num = (hash_num * 33) ^ *ptr; + + hash_num &= 0xff; + return (int)hash_num; +} + +static void +eina_bench_evas_hash(int request) +{ + unsigned int i; + + for (i = 0; i < (unsigned int)request; ++i) + { + char tmp_key[key_size]; + + eina_convert_itoa(i, tmp_key); + eina_strlcat(tmp_key, key_str, key_size); + + evas_hash_gen(tmp_key); + } +} + +typedef struct _Eina_Bench_Ecore Eina_Bench_Ecore; +struct _Eina_Bench_Ecore +{ + char *key; + int value; +}; + +void eina_bench_crc_hash_short(Eina_Benchmark *bench) +{ + key_size = 8; /* Length of string for small strings and pointers */ + key_size -= 5; + repchar(key_size); + + eina_benchmark_register(bench, "superfast-lookup", + EINA_BENCHMARK( + eina_bench_superfast_hash), 10, 80000, 10); + eina_benchmark_register(bench, "djb2-lookup", + EINA_BENCHMARK( + eina_bench_djb2_hash), 10, 80000, 10); + eina_benchmark_register(bench, "murmur", + EINA_BENCHMARK( + eina_bench_murmur_hash), 10, 80000, 10); + eina_benchmark_register(bench, "crchash", + EINA_BENCHMARK( + eina_bench_crchash), 10, 80000, 10); +#ifdef CITYHASH_BENCH + eina_benchmark_register(bench, "cityhash", + EINA_BENCHMARK( + eina_bench_cityhash), 10, 80000, 10); +#endif + +#ifdef EINA_BENCH_HAVE_GLIB + eina_benchmark_register(bench, "ghash-lookup", + EINA_BENCHMARK( + eina_bench_ghash), 10, 80000, 10); +#endif + eina_benchmark_register(bench, "evas-lookup", + EINA_BENCHMARK( + eina_bench_evas_hash), 10, 80000, 10); +} + +void eina_bench_crc_hash_medium(Eina_Benchmark *bench) +{ + key_size = 32; /* Length of medium sized string, normally for filenames */ + key_size -= 5; + repchar(key_size); + + eina_benchmark_register(bench, "superfast-lookup", + EINA_BENCHMARK( + eina_bench_superfast_hash), 10, 80000, 10); + eina_benchmark_register(bench, "djb2-lookup", + EINA_BENCHMARK( + eina_bench_djb2_hash), 10, 80000, 10); + eina_benchmark_register(bench, "murmur", + EINA_BENCHMARK( + eina_bench_murmur_hash), 10, 80000, 10); + eina_benchmark_register(bench, "crchash", + EINA_BENCHMARK( + eina_bench_crchash), 10, 80000, 10); +#ifdef CITYHASH_BENCH + eina_benchmark_register(bench, "cityhash", + EINA_BENCHMARK( + eina_bench_cityhash), 10, 80000, 10); +#endif + +#ifdef EINA_BENCH_HAVE_GLIB + eina_benchmark_register(bench, "ghash-lookup", + EINA_BENCHMARK( + eina_bench_ghash), 10, 80000, 10); +#endif + eina_benchmark_register(bench, "evas-lookup", + EINA_BENCHMARK( + eina_bench_evas_hash), 10, 80000, 10); +} + +void eina_bench_crc_hash_large(Eina_Benchmark *bench) +{ + key_size = 256; /* Length of large strings, normally for filepath */ + key_size -= 5; + repchar(key_size); + + eina_benchmark_register(bench, "superfast-lookup", + EINA_BENCHMARK( + eina_bench_superfast_hash), 10, 80000, 10); + eina_benchmark_register(bench, "djb2-lookup", + EINA_BENCHMARK( + eina_bench_djb2_hash), 10, 80000, 10); + eina_benchmark_register(bench, "murmur", + EINA_BENCHMARK( + eina_bench_murmur_hash), 10, 80000, 10); + eina_benchmark_register(bench, "crchash", + EINA_BENCHMARK( + eina_bench_crchash), 10, 80000, 10); +#ifdef CITYHASH_BENCH + eina_benchmark_register(bench, "cityhash", + EINA_BENCHMARK( + eina_bench_cityhash), 10, 80000, 10); +#endif + +#ifdef EINA_BENCH_HAVE_GLIB + eina_benchmark_register(bench, "ghash-lookup", + EINA_BENCHMARK( + eina_bench_ghash), 10, 80000, 10); +#endif + eina_benchmark_register(bench, "evas-lookup", + EINA_BENCHMARK( + eina_bench_evas_hash), 10, 80000, 10); +}