summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-24 17:36:26 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-26 14:20:24 -0300
commitedd99d24ef797a9b574e2ff0b5821be6e45bc00c (patch)
treecaec2c5364cccf4030d1567151c0870730fa27b2
parent2c043ca2057af6338ad8ff43c044d3b0f602898c (diff)
downloadefl-edd99d24ef797a9b574e2ff0b5821be6e45bc00c.tar.gz
eina: Add benchmarks for eina promises
-rw-r--r--src/benchmarks/eina/Makefile.am1
-rw-r--r--src/benchmarks/eina/eina_bench.c1
-rw-r--r--src/benchmarks/eina/eina_bench.h1
-rw-r--r--src/benchmarks/eina/eina_bench_promise.c359
4 files changed, 362 insertions, 0 deletions
diff --git a/src/benchmarks/eina/Makefile.am b/src/benchmarks/eina/Makefile.am
index da6ceb913d..6d3904c67b 100644
--- a/src/benchmarks/eina/Makefile.am
+++ b/src/benchmarks/eina/Makefile.am
@@ -25,6 +25,7 @@ eina_bench_mempool.c \
eina_bench_stringshare_e17.c \
eina_bench_array.c \
eina_bench_rectangle_pool.c \
+eina_bench_promise.c \
ecore_list.c \
ecore_strings.c \
ecore_hash.c \
diff --git a/src/benchmarks/eina/eina_bench.c b/src/benchmarks/eina/eina_bench.c
index 1ca7e51c18..d037d4959d 100644
--- a/src/benchmarks/eina/eina_bench.c
+++ b/src/benchmarks/eina/eina_bench.c
@@ -47,6 +47,7 @@ static const Eina_Benchmark_Case etc[] = {
{ "Mempool", eina_bench_mempool, EINA_TRUE },
{ "Rectangle_Pool", eina_bench_rectangle_pool, EINA_TRUE },
{ "Render Loop", eina_bench_quadtree, EINA_FALSE },
+ { "Promise", eina_bench_promise, EINA_FALSE },
{ NULL, NULL, EINA_FALSE }
};
diff --git a/src/benchmarks/eina/eina_bench.h b/src/benchmarks/eina/eina_bench.h
index f076d416cc..a38d70433e 100644
--- a/src/benchmarks/eina/eina_bench.h
+++ b/src/benchmarks/eina/eina_bench.h
@@ -34,6 +34,7 @@ void eina_bench_sort(Eina_Benchmark *bench);
void eina_bench_mempool(Eina_Benchmark *bench);
void eina_bench_rectangle_pool(Eina_Benchmark *bench);
void eina_bench_quadtree(Eina_Benchmark *bench);
+void eina_bench_promise(Eina_Benchmark *bench);
/* Specific benchmark. */
void eina_bench_e17(void);
diff --git a/src/benchmarks/eina/eina_bench_promise.c b/src/benchmarks/eina/eina_bench_promise.c
new file mode 100644
index 0000000000..a6ba2bb222
--- /dev/null
+++ b/src/benchmarks/eina/eina_bench_promise.c
@@ -0,0 +1,359 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2008 Cedric Bail
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+#include "Evas_Data.h"
+#include "Ecore_Data.h"
+
+#include "eina_stringshare.h"
+#include "eina_bench.h"
+#include "eina_convert.h"
+#include "eina_main.h"
+
+#include <Eina.h>
+
+struct value_type
+{
+ int x;
+ int y;
+ int w;
+ int h;
+};
+
+void cb(void* data EINA_UNUSED, void* value)
+{
+ struct value_type* p = value;
+ volatile int v = p->x * p->y * p->w * p->h;
+ (void)v;
+}
+
+void pointer_cb(void* data EINA_UNUSED, void* value)
+{
+ struct value_type* p = *(struct value_type**)value;
+ volatile int v = p->x * p->y * p->w * p->h;
+ (void)v;
+}
+
+static void
+eina_bench_promise_sync_then(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+ eina_promise_ref(promise);
+
+ struct value_type v = { 0, 0, 0, 0 };
+ eina_promise_owner_value_set(owner, &v, NULL);
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ eina_promise_then(promise, &cb, NULL, NULL);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_promise_unref(promise);
+ eina_shutdown();
+}
+
+static void
+eina_bench_promise_copy_value_set_after_then(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ struct value_type const v = {0, 0, 0, 0};
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+
+ eina_promise_then(promise, &cb, NULL, NULL);
+ eina_promise_owner_value_set(owner, &v, NULL);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_shutdown();
+}
+
+static void
+eina_bench_promise_no_copy_value_set_after_then(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+ struct value_type* v = eina_promise_owner_buffer_get(owner);
+
+ eina_promise_then(promise, &cb, NULL, NULL);
+
+ v->x = v->y = v-> w = v->h = 0;
+ eina_promise_owner_value_set(owner, NULL, NULL);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_shutdown();
+}
+
+static void
+eina_bench_promise_no_copy_value_set_before_then(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+ struct value_type* v = eina_promise_owner_buffer_get(owner);
+
+ v->x = v->y = v-> w = v->h = 0;
+ eina_promise_owner_value_set(owner, NULL, NULL);
+
+ eina_promise_then(promise, &cb, NULL, NULL);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_shutdown();
+}
+
+static void
+eina_bench_promise_copy_value_set_before_then(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ struct value_type const v = {0, 0, 0, 0};
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+
+ eina_promise_then(promise, &cb, NULL, NULL);
+ eina_promise_owner_value_set(owner, &v, NULL);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_shutdown();
+}
+
+static void indirect_free(void* p)
+{
+ free(*(void**)p);
+}
+
+static void
+eina_bench_promise_pointer_value_set_before_then(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+
+ struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
+ = malloc(sizeof(struct value_type));
+ p->x = p->y = p->w = p->h = 0;
+
+ eina_promise_then(promise, &pointer_cb, NULL, NULL);
+ eina_promise_owner_value_set(owner, NULL, &indirect_free);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_shutdown();
+}
+
+static void
+eina_bench_promise_pointer_value_set_after_then(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+
+ struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
+ = malloc(sizeof(struct value_type));
+ p->x = p->y = p->w = p->h = 0;
+
+ eina_promise_owner_value_set(owner, NULL, &indirect_free);
+ eina_promise_then(promise, &pointer_cb, NULL, NULL);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_shutdown();
+}
+
+static Eina_Mempool* mempool;
+
+static void indirect_mempool_free(void* p)
+{
+ eina_mempool_free(mempool, *(void**)p);
+}
+
+static void
+eina_bench_promise_pointer_value_set_before_then_pooled(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+
+ struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
+ = eina_mempool_malloc(mempool, sizeof(struct value_type));
+ p->x = p->y = p->w = p->h = 0;
+
+ eina_promise_then(promise, &pointer_cb, NULL, NULL);
+ eina_promise_owner_value_set(owner, NULL, &indirect_mempool_free);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_mempool_del(mempool);
+
+ eina_shutdown();
+}
+
+static void
+eina_bench_promise_pointer_value_set_after_then_pooled(int request)
+{
+ const char *tmp;
+ unsigned int j;
+ int i;
+
+ eina_init();
+
+ for (j = 0; j != 200; ++j)
+ for (i = 0; i != request; ++i)
+ {
+ Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
+ Eina_Promise* promise = eina_promise_owner_promise_get(owner);
+
+ struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
+ = eina_mempool_malloc(mempool, sizeof(struct value_type));
+ p->x = p->y = p->w = p->h = 0;
+
+ eina_promise_owner_value_set(owner, NULL, &indirect_mempool_free);
+ eina_promise_then(promise, &pointer_cb, NULL, NULL);
+ }
+
+ /* Suppress warnings as we really don't want to do anything. */
+ (void) tmp;
+
+ eina_shutdown();
+}
+
+void eina_bench_promise(Eina_Benchmark *bench)
+{
+ eina_benchmark_register(bench, "promise synchronous then",
+ EINA_BENCHMARK(
+ eina_bench_promise_sync_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise copy value set after then",
+ EINA_BENCHMARK(
+ eina_bench_promise_copy_value_set_after_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise copy value set before then",
+ EINA_BENCHMARK(
+ eina_bench_promise_copy_value_set_before_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise no copy value set after then",
+ EINA_BENCHMARK(
+ eina_bench_promise_no_copy_value_set_after_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise no copy value set before then",
+ EINA_BENCHMARK(
+ eina_bench_promise_no_copy_value_set_before_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise pointer value set after then",
+ EINA_BENCHMARK(
+ eina_bench_promise_pointer_value_set_after_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise pointer value set before then",
+ EINA_BENCHMARK(
+ eina_bench_promise_pointer_value_set_before_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise pointer value set after then mempool",
+ EINA_BENCHMARK(
+ eina_bench_promise_pointer_value_set_after_then), 100, 20100, 500);
+ eina_benchmark_register(bench, "promise pointer value set before then mempool",
+ EINA_BENCHMARK(
+ eina_bench_promise_pointer_value_set_before_then), 100, 20100, 500);
+}