aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorvivek <vivek.ellur@samsung.com>2015-04-28 23:29:18 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-07 09:53:11 +0200
commiteec4a7bd0caa7d52bff6cc524ca12efa16d1445b (patch)
tree786145e534cfb55b4a43e901cde65b0a75d7fe1a /src
parentevil: remove the need to order the header correctly for Windows. (diff)
downloadefl-eec4a7bd0caa7d52bff6cc524ca12efa16d1445b.tar.gz
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 <vivek.ellur@samsung.com> Reviewers: Sergeant_Whitespace, cedric Reviewed By: cedric Subscribers: Sergeant_Whitespace, cedric Differential Revision: https://phab.enlightenment.org/D2217 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/benchmarks/eina/Makefile.am1
-rw-r--r--src/benchmarks/eina/eina_bench.c3
-rw-r--r--src/benchmarks/eina/eina_bench.h5
-rw-r--r--src/benchmarks/eina/eina_bench_crc_hash.c279
4 files changed, 288 insertions, 0 deletions
diff --git a/src/benchmarks/eina/Makefile.am b/src/benchmarks/eina/Makefile.am
index 9f64d46c5b..da6ceb913d 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 dec210e06d..1ca7e51c18 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 d575822b54..f076d416cc 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 0000000000..b6734489a3
--- /dev/null
+++ b/src/benchmarks/eina/eina_bench_crc_hash.c
@@ -0,0 +1,279 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#ifdef EINA_BENCH_HAVE_GLIB
+# include <glib.h>
+#endif
+
+#include <Eina.h>
+#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);
+}