[gegl] perf: add common bench function to test both opencl and c paths
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] perf: add common bench function to test both opencl and c paths
- Date: Mon, 19 Oct 2015 22:17:42 +0000 (UTC)
commit f767881d87bb2b4d0e64a3fe59ac117d9f595654
Author: André Tupinambá <andrelrt gmail com>
Date: Sat Sep 26 20:04:20 2015 -0300
perf: add common bench function to test both opencl and c paths
perf/test-bcontrast-4x.c | 45 ++++++++++++++--------------
perf/test-bcontrast-minichunk.c | 39 ++++++++++++------------
perf/test-bcontrast.c | 38 ++++++++++++-----------
perf/test-blur.c | 41 ++++++++++++-------------
perf/test-common.h | 62 +++++++++++++++++++++++++++++++++++++--
perf/test-unsharpmask.c | 39 ++++++++++++------------
6 files changed, 162 insertions(+), 102 deletions(-)
---
diff --git a/perf/test-bcontrast-4x.c b/perf/test-bcontrast-4x.c
index 7693a25..8ea9acb 100644
--- a/perf/test-bcontrast-4x.c
+++ b/perf/test-bcontrast-4x.c
@@ -1,35 +1,36 @@
#include "test-common.h"
+void bcontrast4x(GeglBuffer *buffer);
+
gint
main (gint argc,
gchar **argv)
{
- GeglBuffer *buffer, *buffer2;
- GeglNode *gegl, *source, *node1, *node2, *node3, *node4, *sink;
- gint i;
+ GeglBuffer *buffer;
gegl_init (&argc, &argv);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
-
-#define ITERATIONS 16
- test_start ();
- for (i=0;i< ITERATIONS;i++)
- {
- gegl = gegl_node_new ();
- source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
- node1 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
- node2 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
- node3 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
- node4 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
- sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
-
- gegl_node_link_many (source, node1, node2, node3, node4, sink, NULL);
- gegl_node_process (sink);
- g_object_unref (gegl);
- g_object_unref (buffer2);
- }
- test_end ("bcontrast_4x", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
+ bench("bcontrast_4x", buffer, &bcontrast4x);
return 0;
}
+
+void bcontrast4x(GeglBuffer *buffer)
+{
+ GeglBuffer *buffer2;
+ GeglNode *gegl, *source, *node1, *node2, *node3, *node4, *sink;
+
+ gegl = gegl_node_new ();
+ source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+ node1 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
+ node2 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
+ node3 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
+ node4 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
+ sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
+
+ gegl_node_link_many (source, node1, node2, node3, node4, sink, NULL);
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ g_object_unref (buffer2);
+}
diff --git a/perf/test-bcontrast-minichunk.c b/perf/test-bcontrast-minichunk.c
index 8543307..0284bdb 100644
--- a/perf/test-bcontrast-minichunk.c
+++ b/perf/test-bcontrast-minichunk.c
@@ -1,34 +1,35 @@
#include "test-common.h"
+void bcontrast_minichunk(GeglBuffer *buffer);
+
gint
main (gint argc,
gchar **argv)
{
- GeglBuffer *buffer, *buffer2;
- GeglNode *gegl, *source, *node, *sink;
- gint i;
+ GeglBuffer *buffer;
gegl_init (&argc, &argv);
g_object_set (gegl_config (), "chunk-size", 32 * 32, NULL);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
-
-#define ITERATIONS 8
- test_start ();
- for (i=0;i< ITERATIONS;i++)
- {
- gegl = gegl_node_new ();
- source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
- node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
- sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
-
- gegl_node_link_many (source, node, sink, NULL);
- gegl_node_process (sink);
- g_object_unref (gegl);
- g_object_unref (buffer2);
- }
- test_end ("bcontrast-minichunk", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
+ bench("bcontrast-minichunk", buffer, &bcontrast_minichunk);
return 0;
}
+
+void bcontrast_minichunk(GeglBuffer *buffer)
+{
+ GeglBuffer *buffer2;
+ GeglNode *gegl, *source, *node, *sink;
+
+ gegl = gegl_node_new ();
+ source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+ node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
+ sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
+
+ gegl_node_link_many (source, node, sink, NULL);
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ g_object_unref (buffer2);
+}
diff --git a/perf/test-bcontrast.c b/perf/test-bcontrast.c
index dbc4bae..25f86ee 100644
--- a/perf/test-bcontrast.c
+++ b/perf/test-bcontrast.c
@@ -1,32 +1,34 @@
#include "test-common.h"
+void blur(GeglBuffer *buffer);
+
gint
main (gint argc,
gchar **argv)
{
- GeglBuffer *buffer, *buffer2;
- GeglNode *gegl, *source, *node, *sink;
- gint i;
+ GeglBuffer *buffer;
gegl_init (&argc, &argv);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
-#define ITERATIONS 16
- test_start ();
- for (i=0;i< ITERATIONS;i++)
- {
- gegl = gegl_node_new ();
- source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
- node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
- sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
-
- gegl_node_link_many (source, node, sink, NULL);
- gegl_node_process (sink);
- g_object_unref (gegl);
- g_object_unref (buffer2);
- }
- test_end ("bcontrast", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
+ bench("bcontrast", buffer, &blur);
return 0;
}
+
+void blur(GeglBuffer *buffer)
+{
+ GeglBuffer *buffer2;
+ GeglNode *gegl, *source, *node, *sink;
+
+ gegl = gegl_node_new ();
+ source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+ node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
+ sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
+
+ gegl_node_link_many (source, node, sink, NULL);
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ g_object_unref (buffer2);
+}
diff --git a/perf/test-blur.c b/perf/test-blur.c
index d5db4b7..8c01c52 100644
--- a/perf/test-blur.c
+++ b/perf/test-blur.c
@@ -1,35 +1,34 @@
#include "test-common.h"
+void blur(GeglBuffer *buffer);
+
gint
main (gint argc,
gchar **argv)
{
- GeglBuffer *buffer, *buffer2;
- GeglNode *gegl, *source, *node, *sink;
- gint i;
+ GeglBuffer *buffer;
- gegl_init (&argc, &argv);
+ gegl_init(&argc, &argv);
- buffer = test_buffer (1024, 1024, babl_format ("RGBA float"));
+ buffer = test_buffer(1024, 1024, babl_format("RGBA float"));
+ bench("gaussian-blur", buffer, &blur);
+}
-#define ITERATIONS 16
- test_start ();
- for (i=0;i< ITERATIONS;i++)
- {
- gegl = gegl_node_new ();
- source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
- node = gegl_node_new_child (gegl, "operation", "gegl:gaussian-blur",
+void blur(GeglBuffer *buffer)
+{
+ GeglBuffer *buffer2;
+ GeglNode *gegl, *source, *node, *sink;
+
+ gegl = gegl_node_new ();
+ source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+ node = gegl_node_new_child (gegl, "operation", "gegl:gaussian-blur",
"std-dev-x", 0.5,
"std-dev-y", 0.5,
NULL);
- sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
-
- gegl_node_link_many (source, node, sink, NULL);
- gegl_node_process (sink);
- g_object_unref (gegl);
- g_object_unref (buffer2);
- }
- test_end ("gaussian-blur", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
+ sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
- return 0;
+ gegl_node_link_many (source, node, sink, NULL);
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ g_object_unref (buffer2);
}
diff --git a/perf/test-common.h b/perf/test-common.h
index a26cb1d..26a1b7f 100644
--- a/perf/test-common.h
+++ b/perf/test-common.h
@@ -4,26 +4,46 @@
static long ticks_start;
+typedef void (*t_run_perf)(GeglBuffer *buffer);
+
long babl_ticks (void); /* using babl_ticks instead of gegl_ticks
to be able to go further back in time */
void test_start (void);
void test_end (const gchar *id,
glong bytes);
+void test_end_suffix (const gchar *id,
+ const gchar *suffix,
+ glong bytes);
GeglBuffer *test_buffer (gint width,
gint height,
const Babl *format);
+void do_bench(const gchar *id,
+ GeglBuffer *buffer,
+ t_run_perf test_func,
+ gboolean opencl);
+void bench(const gchar *id,
+ GeglBuffer *buffer,
+ t_run_perf test_func );
+
void test_start (void)
{
ticks_start = babl_ticks ();
}
+void test_end_suffix (const gchar *id,
+ const gchar *suffix,
+ glong bytes)
+{
+ long ticks = babl_ticks ()-ticks_start;
+ g_print ("@ %s%s: %.2f megabytes/second\n",
+ id, suffix, (bytes / 1024.0 / 1024.0) / (ticks / 1000000.0));
+}
+
void test_end (const gchar *id,
glong bytes)
{
- long ticks = babl_ticks ()-ticks_start;
- g_print ("@ %s: %.2f megabytes/second\n",
- id, (bytes / 1024.0 / 1024.0) / (ticks / 1000000.0));
+ test_end_suffix (id, "", bytes);
}
/* create a test buffer of random data in -0.5 to 2.0 range
@@ -43,3 +63,39 @@ GeglBuffer *test_buffer (gint width,
g_free (buf);
return buffer;
}
+
+void do_bench (const gchar *id,
+ GeglBuffer *buffer,
+ t_run_perf test_func,
+ gboolean opencl)
+{
+ gchar* suffix = "";
+
+ g_object_set(G_OBJECT(gegl_config()),
+ "use-opencl", opencl,
+ NULL);
+
+ if (opencl)
+ suffix = " (OpenCL)";
+
+ // warm up
+ test_func(buffer);
+
+#define ITERATIONS 16
+ test_start ();
+ for (int i=0; i<ITERATIONS; ++i)
+ {
+ test_func(buffer);
+ }
+ test_end_suffix (id, suffix, gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
+#undef ITERATIONS
+}
+
+void bench (const gchar *id,
+ GeglBuffer *buffer,
+ t_run_perf test_func)
+{
+ do_bench(id, buffer, test_func, FALSE );
+ do_bench(id, buffer, test_func, TRUE );
+}
+
diff --git a/perf/test-unsharpmask.c b/perf/test-unsharpmask.c
index 38835a8..0095825 100644
--- a/perf/test-unsharpmask.c
+++ b/perf/test-unsharpmask.c
@@ -1,35 +1,36 @@
#include "test-common.h"
+void unsharpmask(GeglBuffer *buffer);
+
gint
main (gint argc,
gchar **argv)
{
- GeglBuffer *buffer, *buffer2;
- GeglNode *gegl, *source, *node, *sink;
- gint i;
+ GeglBuffer *buffer;
gegl_init (&argc, &argv);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
+ bench("unsharp-mask", buffer, &unsharpmask);
+
+ return 0;
+}
-#define ITERATIONS 8
- test_start ();
- for (i=0;i< ITERATIONS;i++)
- {
- gegl = gegl_node_new ();
- source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
- node = gegl_node_new_child (gegl, "operation", "gegl:unsharp-mask",
+void unsharpmask(GeglBuffer *buffer)
+{
+ GeglBuffer *buffer2;
+ GeglNode *gegl, *source, *node, *sink;
+
+ gegl = gegl_node_new ();
+ source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+ node = gegl_node_new_child (gegl, "operation", "gegl:unsharp-mask",
"std-dev", 3.1,
"scale", 1.2,
NULL);
- sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
+ sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
- gegl_node_link_many (source, node, sink, NULL);
- gegl_node_process (sink);
- g_object_unref (gegl);
- g_object_unref (buffer2);
- }
- test_end ("unsharp-mask", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
-
- return 0;
+ gegl_node_link_many (source, node, sink, NULL);
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ g_object_unref (buffer2);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]