perf/micro: Test wide vs hairline strokes

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2011-08-12 21:58:55 +01:00
parent ccbd7281b2
commit e9d41054f9
8 changed files with 404 additions and 16 deletions

View file

@ -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 }

View file

@ -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);

View file

@ -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 \

View file

@ -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--)
@ -69,6 +67,20 @@ do_many_curves_stroked (cairo_t *cr, int width, int height, int loops)
return cairo_perf_timer_elapsed ();
}
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)
{
@ -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);
}

View file

@ -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);
}

View file

@ -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 ();

184
perf/micro/wide-fills.c Normal file
View file

@ -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);
}

185
perf/micro/wide-strokes.c Normal file
View file

@ -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);
}