[Pixman] [PATCH 1/3] test/scaling-bench.c: New benchmark for bilinear scaling

Søren Sandmann Pedersen soren.sandmann at gmail.com
Mon Jul 29 02:03:27 PDT 2013


This new benchmark scales a 320 x 240 test a8r8g8b8 image by all
ratios from 0.1, 0.2, ... up to 10.0 and reports the time it to took
to do each of the scaling operations, and the time spent per
destination pixel.

The times reported for the scaling operations are given in seconds,
the times-per-pixel are in tenths-of-a-microsecond.
---
 test/Makefile.sources |    1 +
 test/scaling-bench.c  |   64 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)
 create mode 100644 test/scaling-bench.c

diff --git a/test/Makefile.sources b/test/Makefile.sources
index b5fc740..2fabdb5 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -33,6 +33,7 @@ OTHERPROGRAMS =                 \
 	lowlevel-blt-bench	\
 	radial-perf-test	\
         check-formats           \
+	scaling-bench		\
 	$(NULL)
 
 # Utility functions
diff --git a/test/scaling-bench.c b/test/scaling-bench.c
new file mode 100644
index 0000000..4940d43
--- /dev/null
+++ b/test/scaling-bench.c
@@ -0,0 +1,64 @@
+#include <stdlib.h>
+#include "utils.h"
+
+#define SOURCE_WIDTH 320
+#define SOURCE_HEIGHT 240
+
+static pixman_image_t *
+make_source (void)
+{
+    size_t n_bytes = (SOURCE_WIDTH + 2) * (SOURCE_HEIGHT + 2) * 4;
+    uint32_t *data = malloc (n_bytes);
+    pixman_image_t *source;
+
+    prng_randmemset (data, n_bytes, 0);
+    
+    source = pixman_image_create_bits (
+	PIXMAN_a8r8g8b8, SOURCE_WIDTH + 2, SOURCE_HEIGHT + 2,
+	data,
+	(SOURCE_WIDTH + 2) * 4);
+
+    pixman_image_set_filter (source, PIXMAN_FILTER_BILINEAR, NULL, 0);
+
+    return source;
+}
+
+int
+main ()
+{
+    double scale;
+    pixman_image_t *src;
+
+    prng_srand (23874);
+    
+    src = make_source ();
+    for (scale = 0.1; scale < 10.005; scale += 0.01)
+    {
+	int dest_width = SOURCE_WIDTH * scale + 0.5;
+	int dest_height = SOURCE_HEIGHT * scale + 0.5;
+	pixman_fixed_t s = (1 / scale) * 65536.0 + 0.5;
+	pixman_transform_t transform;
+	pixman_image_t *dest;
+	double t1, t2;
+
+	pixman_transform_init_scale (&transform, s, s);
+	pixman_image_set_transform (src, &transform);
+	
+	dest = pixman_image_create_bits (
+	    PIXMAN_a8r8g8b8, dest_width, dest_height, NULL, -1);
+
+	t1 = gettime();
+	pixman_image_composite (
+	    PIXMAN_OP_OVER, src, NULL, dest,
+	    scale, scale, 0, 0, 0, 0, dest_width, dest_height);
+	t2 = gettime();
+	
+	printf ("%f : %d %d => %d %d : %f : %f\n",
+		scale, SOURCE_WIDTH, SOURCE_HEIGHT, dest_width, dest_height,
+		t2 - t1, ((t2 - t1) / (dest_width * dest_height)) * 10000000);
+
+	pixman_image_unref (dest);
+    }
+
+    return 0;
+}
-- 
1.7.1



More information about the Pixman mailing list