[gegl] perf: add a test measuring sampler performance
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] perf: add a test measuring sampler performance
- Date: Thu, 19 Jun 2014 22:39:25 +0000 (UTC)
commit 7988a8352db3a3c9e8efc631cdc415a6981db362
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Jun 20 00:33:17 2014 +0200
perf: add a test measuring sampler performance
perf/Makefile.am | 2 +
perf/test-gegl-buffer-access.c | 120 +++++++++++++-
perf/test-samplers.c | 355 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 471 insertions(+), 6 deletions(-)
---
diff --git a/perf/Makefile.am b/perf/Makefile.am
index df85665..8ce576b 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -7,6 +7,7 @@ noinst_PROGRAMS = \
test-unsharpmask \
test-bcontrast-4x \
test-gegl-buffer-access \
+ test-samplers \
test-rotate
INCLUDES = \
@@ -43,6 +44,7 @@ test_bcontrast_megachunk_SOURCES = test-bcontrast-megachunk.c
test_bcontrast_4x_SOURCES = test-bcontrast-4x.c
test_unsharpmask_SOURCES = test-unsharpmask.c
test_gegl_buffer_access_SOURCES = test-gegl-buffer-access.c
+test_samplers_SOURCES = test-samplers.c
EXTRA_DIST = Makefile-retrospect Makefile-tests create-report.rb test-common.h
diff --git a/perf/test-gegl-buffer-access.c b/perf/test-gegl-buffer-access.c
index 63608ef..a586d3b 100644
--- a/perf/test-gegl-buffer-access.c
+++ b/perf/test-gegl-buffer-access.c
@@ -1,30 +1,33 @@
#include "test-common.h"
+#define BPP 16
+
gint
main (gint argc,
gchar **argv)
{
GeglBuffer *buffer;
GeglRectangle bound = {0, 0, 4024, 4024};
+ const Babl *format;
gchar *buf;
gint i;
gegl_init (NULL, NULL);
- buffer = gegl_buffer_new (&bound, babl_format ("RGBA float"));
- buf = g_malloc0 (bound.width * bound.height * 16);
+ format = babl_format ("RGBA float");
+ buffer = gegl_buffer_new (&bound, format);
+ buf = g_malloc0 (bound.width * bound.height * BPP);
-#define ITERATIONS 8
+#define ITERATIONS 4
/* pre-initialize */
gegl_buffer_set (buffer, &bound, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE);
-
test_start ();
for (i=0;i<ITERATIONS;i++)
{
gegl_buffer_get (buffer, &bound, 1.0, NULL, buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
}
- test_end ("gegl_buffer_get", bound.width * bound.height * ITERATIONS * 16);
+ test_end ("gegl_buffer_get", bound.width * bound.height * ITERATIONS * BPP);
test_start ();
@@ -32,7 +35,112 @@ main (gint argc,
{
gegl_buffer_set (buffer, &bound, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE);
}
- test_end ("gegl_buffer_set", bound.width * bound.height * ITERATIONS * 16);
+ test_end ("gegl_buffer_set", bound.width * bound.height * ITERATIONS * BPP);
+
+
+ format = babl_format ("RGBA float");
+
+ {
+#define SAMPLES 150000
+ gint rands[SAMPLES*2];
+
+ for (i = 0; i < SAMPLES; i ++)
+ {
+ rands[i*2] = rand()%1000;
+ rands[i*2+1] = rand()%1000;
+ rands[i*2] = i / 1000;
+ rands[i*2+1] = i % 1000;
+ }
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+#if 1
+ GeglRectangle rect = {x, y, 1, 1};
+ gegl_buffer_set (buffer, &rect, 0, format, (void*)&px[0], GEGL_AUTO_ROWSTRIDE);
+#else
+ gegl_buffer_set_pixel (buffer, x, y, format, (void*)&px[0], 3);
+#endif
+ }
+ }
+ test_end ("gegl_buffer_set 1x1", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ GeglRectangle rect = {x, y, 1, 1};
+ gegl_buffer_get (buffer, &rect, 1.0, format, (void*)&px[0],
+ GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_get 1x1", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
+ GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_sample nearest", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_NEAREST);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("gegl_sampler_get nearest", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_NEAREST);
+ GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("sampler_get_fun nearest", SAMPLES * ITERATIONS * BPP);
+ }
g_free (buf);
g_object_unref (buffer);
diff --git a/perf/test-samplers.c b/perf/test-samplers.c
new file mode 100644
index 0000000..7ac0705
--- /dev/null
+++ b/perf/test-samplers.c
@@ -0,0 +1,355 @@
+#include "test-common.h"
+
+#define BPP 16
+#define ITERATIONS 4
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ GeglBuffer *buffer;
+ GeglRectangle bound = {0, 0, 4024, 4024};
+ const Babl *format;
+ gchar *buf;
+ gint i;
+
+ gegl_init (NULL, NULL);
+ format = babl_format ("RGBA float");
+ buffer = gegl_buffer_new (&bound, format);
+ buf = g_malloc0 (bound.width * bound.height * BPP);
+
+ /* pre-initialize */
+ gegl_buffer_set (buffer, &bound, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE);
+
+ format = babl_format ("RGBA float");
+
+ {
+#define SAMPLES 150000
+ gint rands[SAMPLES*2];
+
+ for (i = 0; i < SAMPLES; i ++)
+ {
+ rands[i*2] = rand()%1000;
+ rands[i*2+1] = rand()%1000;
+ rands[i*2] = i / 1000;
+ rands[i*2+1] = i % 1000;
+ }
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+#if 1
+ GeglRectangle rect = {x, y, 1, 1};
+ gegl_buffer_set (buffer, &rect, 0, format, (void*)&px[0], GEGL_AUTO_ROWSTRIDE);
+#else
+ gegl_buffer_set_pixel (buffer, x, y, format, (void*)&px[0], 3);
+#endif
+ }
+ }
+ test_end ("gegl_buffer_set 1x1", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ GeglRectangle rect = {x, y, 1, 1};
+ gegl_buffer_get (buffer, &rect, 1.0, format, (void*)&px[0],
+ GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_get 1x1", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
+ GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_sample nearest", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_NEAREST);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("gegl_sampler_get nearest", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_NEAREST);
+ GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("sampler_get_fun nearest", SAMPLES * ITERATIONS * BPP);
+
+
+
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
+ GEGL_SAMPLER_LINEAR, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_sample linear", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_LINEAR);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("gegl_sampler_get linear", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_LINEAR);
+ GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("sampler_get_fun linear", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
+ GEGL_SAMPLER_CUBIC, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_sample cubic", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_CUBIC);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("gegl_sampler_get cubic", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_CUBIC);
+ GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("sampler_get_fun cubic", SAMPLES * ITERATIONS * BPP);
+
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
+ GEGL_SAMPLER_NOHALO, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_sample nohalo", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_NOHALO);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("gegl_sampler_get nohalo", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_NOHALO);
+ GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("sampler_get_fun nohalo", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
+ GEGL_SAMPLER_LOHALO, GEGL_ABYSS_NONE);
+ }
+ }
+ test_end ("gegl_buffer_sample lohalo", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_LOHALO);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("gegl_sampler_get lohalo", SAMPLES * ITERATIONS * BPP);
+
+ test_start ();
+ for (i = 0; i < ITERATIONS; i++)
+ {
+ int j;
+ float px[4] = {0.2, 0.4, 0.1, 0.5};
+ GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
+ GEGL_SAMPLER_LOHALO);
+ GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
+
+ for (j = 0; j < SAMPLES; j ++)
+ {
+ int x = rands[j*2];
+ int y = rands[j*2+1];
+ sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
+ }
+
+ g_object_unref (sampler);
+ }
+ test_end ("sampler_get_fun lohalo", SAMPLES * ITERATIONS * BPP);
+
+ }
+
+
+
+ g_free (buf);
+ g_object_unref (buffer);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]