eina: Add benchmarks for eina promises
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Tue, 24 May 2016 20:36:26 +0000 (17:36 -0300)
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Thu, 26 May 2016 17:20:24 +0000 (14:20 -0300)
src/benchmarks/eina/Makefile.am
src/benchmarks/eina/eina_bench.c
src/benchmarks/eina/eina_bench.h
src/benchmarks/eina/eina_bench_promise.c [new file with mode: 0644]

index da6ceb9..6d3904c 100644 (file)
@@ -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 \
index 1ca7e51..d037d49 100644 (file)
@@ -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 }
 };
 
index f076d41..a38d704 100644 (file)
@@ -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 (file)
index 0000000..a6ba2bb
--- /dev/null
@@ -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);
+}