summaryrefslogtreecommitdiff
path: root/perf
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-08-12 21:58:55 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-08-13 09:30:26 +0100
commite9d41054f954e84b317ca756edb4cd58dcad6362 (patch)
treeaa420e56787b1578778c86e2ec5b9e60cca84e05 /perf
parentccbd7281b25f4b25a4c324aa815b94d7de76ac90 (diff)
perf/micro: Test wide vs hairline strokes
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'perf')
-rw-r--r--perf/cairo-perf-micro.c8
-rw-r--r--perf/cairo-perf.h2
-rw-r--r--perf/micro/Makefile.sources2
-rw-r--r--perf/micro/many-curves.c19
-rw-r--r--perf/micro/many-fills.c10
-rw-r--r--perf/micro/many-strokes.c10
-rw-r--r--perf/micro/wide-fills.c184
-rw-r--r--perf/micro/wide-strokes.c185
8 files changed, 404 insertions, 16 deletions
diff --git a/perf/cairo-perf-micro.c b/perf/cairo-perf-micro.c
index 11071392..55ca0e85 100644
--- a/perf/cairo-perf-micro.c
+++ b/perf/cairo-perf-micro.c
@@ -565,9 +565,11 @@ const cairo_perf_case_t perf_cases[] = {
{ dragon, 1024, 1024 },
{ pythagoras_tree, 768, 768 },
{ intersections, 512, 512 },
- { many_strokes, 64, 512 },
- { many_fills, 64, 512 },
- { many_curves, 64, 512 },
+ { many_strokes, 32, 512 },
+ { wide_strokes, 32, 512 },
+ { many_fills, 32, 512 },
+ { wide_fills, 32, 512 },
+ { many_curves, 32, 512 },
{ spiral, 512, 512 },
{ wave, 500, 500 },
{ NULL }
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 3921222f..5da6ee05 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -212,7 +212,9 @@ CAIRO_PERF_DECL (intersections);
CAIRO_PERF_DECL (spiral);
CAIRO_PERF_DECL (wave);
CAIRO_PERF_DECL (many_strokes);
+CAIRO_PERF_DECL (wide_strokes);
CAIRO_PERF_DECL (many_fills);
+CAIRO_PERF_DECL (wide_fills);
CAIRO_PERF_DECL (many_curves);
CAIRO_PERF_DECL (curve);
diff --git a/perf/micro/Makefile.sources b/perf/micro/Makefile.sources
index 5de4d43c..1fe8be1b 100644
--- a/perf/micro/Makefile.sources
+++ b/perf/micro/Makefile.sources
@@ -29,7 +29,9 @@ libcairo_perf_micro_sources = \
pythagoras-tree.c \
intersections.c \
many-strokes.c \
+ wide-strokes.c \
many-fills.c \
+ wide-fills.c \
many-curves.c \
curve.c \
spiral.c \
diff --git a/perf/micro/many-curves.c b/perf/micro/many-curves.c
index aec92bf9..b44fd135 100644
--- a/perf/micro/many-curves.c
+++ b/perf/micro/many-curves.c
@@ -55,8 +55,6 @@ do_many_curves_stroked (cairo_t *cr, int width, int height, int loops)
cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
}
- cairo_set_line_width (cr, 2.);
-
cairo_perf_timer_start ();
while (loops--)
@@ -70,6 +68,20 @@ do_many_curves_stroked (cairo_t *cr, int width, int height, int loops)
}
static cairo_perf_ticks_t
+do_many_curves_hair_stroked (cairo_t *cr, int width, int height, int loops)
+{
+ cairo_set_line_width (cr, 1.);
+ return do_many_curves_stroked (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+do_many_curves_wide_stroked (cairo_t *cr, int width, int height, int loops)
+{
+ cairo_set_line_width (cr, 5.);
+ return do_many_curves_stroked (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
do_many_curves_filled (cairo_t *cr, int width, int height, int loops)
{
int count;
@@ -114,6 +126,7 @@ many_curves (cairo_perf_t *perf, cairo_t *cr, int width, int height)
cairo_set_source_rgb (cr, 1., 1., 1.);
- cairo_perf_run (perf, "many-curves-stroked", do_many_curves_stroked, NULL);
+ cairo_perf_run (perf, "many-curves-hair-stroked", do_many_curves_hair_stroked, NULL);
+ cairo_perf_run (perf, "many-curves-wide-stroked", do_many_curves_wide_stroked, NULL);
cairo_perf_run (perf, "many-curves-filled", do_many_curves_filled, NULL);
}
diff --git a/perf/micro/many-fills.c b/perf/micro/many-fills.c
index 8c012aab..c52e1bf3 100644
--- a/perf/micro/many-fills.c
+++ b/perf/micro/many-fills.c
@@ -54,7 +54,7 @@ do_many_fills_ha (cairo_t *cr, int width, int height, int loops)
for (count = 0; count < 1000; count++) {
double y = floor (uniform_random (0, height));
double x = floor (uniform_random (0, width));
- cairo_rectangle (cr, x, y, ceil (uniform_random (0, width)) - x, 2);
+ cairo_rectangle (cr, x, y, ceil (uniform_random (0, width)) - x, 1);
}
cairo_perf_timer_start ();
@@ -78,7 +78,7 @@ do_many_fills_h (cairo_t *cr, int width, int height, int loops)
for (count = 0; count < 1000; count++) {
double y = uniform_random (0, height);
double x = uniform_random (0, width);
- cairo_rectangle (cr, x, y, uniform_random (0, width) - x, 2);
+ cairo_rectangle (cr, x, y, uniform_random (0, width) - x, 1);
}
cairo_perf_timer_start ();
@@ -102,7 +102,7 @@ do_many_fills_va (cairo_t *cr, int width, int height, int loops)
for (count = 0; count < 1000; count++) {
double x = floor (uniform_random (0, width));
double y = floor (uniform_random (0, height));
- cairo_rectangle (cr, x, y, 2, ceil (uniform_random (0, height) - y));
+ cairo_rectangle (cr, x, y, 1, ceil (uniform_random (0, height) - y));
}
cairo_perf_timer_start ();
@@ -126,7 +126,7 @@ do_many_fills_v (cairo_t *cr, int width, int height, int loops)
for (count = 0; count < 1000; count++) {
double x = uniform_random (0, width);
double y = uniform_random (0, height);
- cairo_rectangle (cr, x, y, 2, uniform_random (0, height) - y);
+ cairo_rectangle (cr, x, y, 1, uniform_random (0, height) - y);
}
cairo_perf_timer_start ();
@@ -154,7 +154,7 @@ do_many_fills (cairo_t *cr, int width, int height, int loops)
uniform_random (0, width),
uniform_random (0, height));
cairo_rotate (cr, uniform_random (-M_PI,M_PI));
- cairo_rectangle (cr, 0, 0, uniform_random (0, width), 2);
+ cairo_rectangle (cr, 0, 0, uniform_random (0, width), 1);
cairo_restore (cr);
}
diff --git a/perf/micro/many-strokes.c b/perf/micro/many-strokes.c
index f5b3a8cb..8ef18768 100644
--- a/perf/micro/many-strokes.c
+++ b/perf/micro/many-strokes.c
@@ -50,7 +50,7 @@ do_many_strokes_ha (cairo_t *cr, int width, int height, int loops)
cairo_line_to (cr, ceil (uniform_random (0, width)), h);
}
- cairo_set_line_width (cr, 2.);
+ cairo_set_line_width (cr, 1.);
cairo_perf_timer_start ();
@@ -76,7 +76,7 @@ do_many_strokes_h (cairo_t *cr, int width, int height, int loops)
cairo_line_to (cr, uniform_random (0, width), h);
}
- cairo_set_line_width (cr, 2.);
+ cairo_set_line_width (cr, 1.);
cairo_perf_timer_start ();
@@ -102,7 +102,7 @@ do_many_strokes_va (cairo_t *cr, int width, int height, int loops)
cairo_line_to (cr, v, ceil (uniform_random (0, height)));
}
- cairo_set_line_width (cr, 2.);
+ cairo_set_line_width (cr, 1.);
cairo_perf_timer_start ();
@@ -128,7 +128,7 @@ do_many_strokes_v (cairo_t *cr, int width, int height, int loops)
cairo_line_to (cr, v, uniform_random (0, height));
}
- cairo_set_line_width (cr, 2.);
+ cairo_set_line_width (cr, 1.);
cairo_perf_timer_start ();
@@ -155,7 +155,7 @@ do_many_strokes (cairo_t *cr, int width, int height, int loops)
uniform_random (0, height));
}
- cairo_set_line_width (cr, 2.);
+ cairo_set_line_width (cr, 1.);
cairo_perf_timer_start ();
diff --git a/perf/micro/wide-fills.c b/perf/micro/wide-fills.c
new file mode 100644
index 00000000..a4adc489
--- /dev/null
+++ b/perf/micro/wide-fills.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+
+/* This is a variant on wide strokes where we precompute
+ * a simplified stroke-to-path.
+ * When we have a real stroke-to-path, it would useful to compare the cost
+ * of stroking vs filling the "identical" paths.
+ */
+
+#include "cairo-perf.h"
+
+static uint32_t state;
+
+static double
+uniform_random (double minval, double maxval)
+{
+ static uint32_t const poly = 0x9a795537U;
+ uint32_t n = 32;
+ while (n-->0)
+ state = 2*state < state ? (2*state ^ poly) : 2*state;
+ return minval + state * (maxval - minval) / 4294967296.0;
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_ha (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double y = floor (uniform_random (0, height));
+ double x = floor (uniform_random (0, width));
+ cairo_rectangle (cr, x, y, ceil (uniform_random (0, width)) - x, 5);
+ }
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_fill_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_h (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double y = uniform_random (0, height);
+ double x = uniform_random (0, width);
+ cairo_rectangle (cr, x, y, uniform_random (0, width) - x, 5);
+ }
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_fill_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_va (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double x = floor (uniform_random (0, width));
+ double y = floor (uniform_random (0, height));
+ cairo_rectangle (cr, x, y, 5, ceil (uniform_random (0, height) - y));
+ }
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_fill_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_v (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double x = uniform_random (0, width);
+ double y = uniform_random (0, height);
+ cairo_rectangle (cr, x, y, 5, uniform_random (0, height) - y);
+ }
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_fill_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ /* lots and lots of overlapping stroke-like fills */
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ cairo_save (cr);
+ cairo_translate (cr,
+ uniform_random (0, width),
+ uniform_random (0, height));
+ cairo_rotate (cr, uniform_random (-M_PI,M_PI));
+ cairo_rectangle (cr, 0, 0, uniform_random (0, width), 5);
+ cairo_restore (cr);
+ }
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_fill_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+void
+wide_fills (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+ if (! cairo_perf_can_run (perf, "wide-fills", NULL))
+ return;
+
+ cairo_perf_run (perf, "wide-fills-halign", do_wide_fills_ha, NULL);
+ cairo_perf_run (perf, "wide-fills-valign", do_wide_fills_va, NULL);
+ cairo_perf_run (perf, "wide-fills-horizontal", do_wide_fills_h, NULL);
+ cairo_perf_run (perf, "wide-fills-vertical", do_wide_fills_v, NULL);
+ cairo_perf_run (perf, "wide-fills-random", do_wide_fills, NULL);
+}
diff --git a/perf/micro/wide-strokes.c b/perf/micro/wide-strokes.c
new file mode 100644
index 00000000..450d6a9a
--- /dev/null
+++ b/perf/micro/wide-strokes.c
@@ -0,0 +1,185 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#include "cairo-perf.h"
+
+static uint32_t state;
+
+static double
+uniform_random (double minval, double maxval)
+{
+ static uint32_t const poly = 0x9a795537U;
+ uint32_t n = 32;
+ while (n-->0)
+ state = 2*state < state ? (2*state ^ poly) : 2*state;
+ return minval + state * (maxval - minval) / 4294967296.0;
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_ha (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double h = floor (uniform_random (0, height));
+ cairo_move_to (cr, floor (uniform_random (0, width)), h);
+ cairo_line_to (cr, ceil (uniform_random (0, width)), h);
+ }
+
+ cairo_set_line_width (cr, 5.);
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_stroke_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_h (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double h = uniform_random (0, height);
+ cairo_move_to (cr, uniform_random (0, width), h);
+ cairo_line_to (cr, uniform_random (0, width), h);
+ }
+
+ cairo_set_line_width (cr, 5.);
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_stroke_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_va (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double v = floor (uniform_random (0, width));
+ cairo_move_to (cr, v, floor (uniform_random (0, height)));
+ cairo_line_to (cr, v, ceil (uniform_random (0, height)));
+ }
+
+ cairo_set_line_width (cr, 5.);
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_stroke_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_v (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ double v = uniform_random (0, width);
+ cairo_move_to (cr, v, uniform_random (0, height));
+ cairo_line_to (cr, v, uniform_random (0, height));
+ }
+
+ cairo_set_line_width (cr, 5.);
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_stroke_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes (cairo_t *cr, int width, int height, int loops)
+{
+ int count;
+
+ /* lots and lots of overlapping strokes */
+ state = 0xc0ffee;
+ for (count = 0; count < 1000; count++) {
+ cairo_line_to (cr,
+ uniform_random (0, width),
+ uniform_random (0, height));
+ }
+
+ cairo_set_line_width (cr, 5.);
+
+ cairo_perf_timer_start ();
+
+ while (loops--)
+ cairo_stroke_preserve (cr);
+
+ cairo_perf_timer_stop ();
+
+ cairo_new_path (cr);
+
+ return cairo_perf_timer_elapsed ();
+}
+
+void
+wide_strokes (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+ if (! cairo_perf_can_run (perf, "wide-strokes", NULL))
+ return;
+
+ cairo_set_source_rgb (cr, 1., 1., 1.);
+
+ cairo_perf_run (perf, "wide-strokes-halign", do_wide_strokes_ha, NULL);
+ cairo_perf_run (perf, "wide-strokes-valign", do_wide_strokes_va, NULL);
+ cairo_perf_run (perf, "wide-strokes-horizontal", do_wide_strokes_h, NULL);
+ cairo_perf_run (perf, "wide-strokes-vertical", do_wide_strokes_v, NULL);
+ cairo_perf_run (perf, "wide-strokes-random", do_wide_strokes, NULL);
+}