diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-08-03 22:23:19 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-08-06 10:15:40 +0100 |
commit | 0db9e010fa70c65451d324cc9c0ade989f77fedd (patch) | |
tree | e249038d900a7afd7e3ede351517b74fd4be5764 | |
parent | 60c574ad062f3d8526056942bb7c9e71610a2773 (diff) |
[perf] Calibrate tests to run for at least 2 seconds
By ensuring that tests take longer than a couple of seconds we eliminate
systematic errors in our measurements. However, we also effectively
eliminate the synchronisation overhead. To compensate, we attempt to
estimate the overhead by reporting the difference between a single
instance and the minimum averaged instance.
-rw-r--r-- | perf/box-outline.c | 14 | ||||
-rw-r--r-- | perf/cairo-perf-report.c | 4 | ||||
-rw-r--r-- | perf/cairo-perf.c | 39 | ||||
-rw-r--r-- | perf/cairo-perf.h | 2 | ||||
-rw-r--r-- | perf/composite-checker.c | 22 | ||||
-rw-r--r-- | perf/dragon.c | 142 | ||||
-rw-r--r-- | perf/fill.c | 21 | ||||
-rw-r--r-- | perf/glyphs.c | 32 | ||||
-rw-r--r-- | perf/intersections.c | 27 | ||||
-rw-r--r-- | perf/long-dashed-lines.c | 9 | ||||
-rw-r--r-- | perf/long-lines.c | 68 | ||||
-rw-r--r-- | perf/mask.c | 45 | ||||
-rw-r--r-- | perf/mosaic.c | 38 | ||||
-rw-r--r-- | perf/paint-with-alpha.c | 5 | ||||
-rw-r--r-- | perf/paint.c | 5 | ||||
-rw-r--r-- | perf/pattern_create_radial.c | 24 | ||||
-rw-r--r-- | perf/pythagoras-tree.c | 20 | ||||
-rw-r--r-- | perf/rectangles.c | 38 | ||||
-rw-r--r-- | perf/rounded-rectangles.c | 47 | ||||
-rw-r--r-- | perf/spiral.c | 51 | ||||
-rw-r--r-- | perf/stroke.c | 19 | ||||
-rw-r--r-- | perf/subimage_copy.c | 7 | ||||
-rw-r--r-- | perf/tessellate.c | 17 | ||||
-rw-r--r-- | perf/text.c | 27 | ||||
-rw-r--r-- | perf/twin.c | 29 | ||||
-rw-r--r-- | perf/unaligned-clip.c | 37 | ||||
-rw-r--r-- | perf/world-map.c | 78 | ||||
-rw-r--r-- | perf/zrusin.c | 10 |
28 files changed, 496 insertions, 381 deletions
diff --git a/perf/box-outline.c b/perf/box-outline.c index 2d826e68..6b97b081 100644 --- a/perf/box-outline.c +++ b/perf/box-outline.c @@ -41,7 +41,7 @@ */ static cairo_perf_ticks_t -box_outline_stroke (cairo_t *cr, int width, int height) +box_outline_stroke (cairo_t *cr, int width, int height, int loops) { cairo_set_source_rgb (cr, 0, 0, 1); /* blue */ cairo_paint (cr); @@ -54,15 +54,18 @@ box_outline_stroke (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_stroke (cr); + while (loops--) + cairo_stroke_preserve (cr); cairo_perf_timer_stop (); + cairo_new_path (cr); + return cairo_perf_timer_elapsed (); } static cairo_perf_ticks_t -box_outline_fill (cairo_t *cr, int width, int height) +box_outline_fill (cairo_t *cr, int width, int height, int loops) { cairo_set_source_rgb (cr, 0, 0, 1); /* blue */ cairo_paint (cr); @@ -78,10 +81,13 @@ box_outline_fill (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_fill (cr); + while (loops--) + cairo_fill_preserve (cr); cairo_perf_timer_stop (); + cairo_new_path (cr); + return cairo_perf_timer_elapsed (); } diff --git a/perf/cairo-perf-report.c b/perf/cairo-perf-report.c index 65340a1e..1690e62a 100644 --- a/perf/cairo-perf-report.c +++ b/perf/cairo-perf-report.c @@ -49,7 +49,7 @@ typedef ptrdiff_t ssize_t; #endif -#ifndef __USE_GNU +#if !defined (__USE_GNU) && !defined(__USE_XOPEN2K8) static ssize_t getline (char **lineptr, size_t *n, FILE *stream); @@ -227,7 +227,7 @@ test_report_parse (test_report_t *report, char *line, char *configuration) * as needed. These aren't necessary full-fledged general purpose * implementations. They just get the job done for our purposes. */ -#ifndef __USE_GNU +#if !defined (__USE_GNU) && !defined(__USE_XOPEN2K8) #define POORMANS_GETLINE_BUFFER_SIZE (65536) static ssize_t getline (char **lineptr, size_t *n, FILE *stream) diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c index 792120b9..21d48f42 100644 --- a/perf/cairo-perf.c +++ b/perf/cairo-perf.c @@ -191,9 +191,9 @@ cairo_perf_run (cairo_perf_t *perf, if (perf->summary) { fprintf (perf->summary, - "[ # ] %8s.%-4s %28s %8s %8s %5s %5s %s\n", + "[ # ] %8s.%-4s %28s %8s %8s %5s %5s %s %s\n", "backend", "content", "test-size", "min(ticks)", "min(ms)", "median(ms)", - "stddev.", "iterations"); + "stddev.", "iterations", "overhead"); } first_run = FALSE; } @@ -208,7 +208,7 @@ cairo_perf_run (cairo_perf_t *perf, name, perf->target->name, _content_to_string (perf->target->content, 0), perf->size); - perf_func (perf->cr, perf->size, perf->size); + perf_func (perf->cr, perf->size, perf->size, 1); status = cairo_surface_write_to_png (cairo_get_target (perf->cr), filename); if (status) { fprintf (stderr, "Failed to generate output check '%s': %s\n", @@ -221,6 +221,9 @@ cairo_perf_run (cairo_perf_t *perf, has_similar = cairo_perf_has_similar (perf); for (similar = 0; similar <= has_similar; similar++) { + cairo_perf_ticks_t calibration0, calibration; + unsigned loops; + if (perf->summary) { fprintf (perf->summary, "[%3d] %8s.%-5s %26s.%-3d ", @@ -230,22 +233,41 @@ cairo_perf_run (cairo_perf_t *perf, fflush (perf->summary); } - /* We run one iteration in advance to warm caches, etc. */ + /* We run one iteration in advance to warm caches and calibrate. */ cairo_perf_yield (); if (similar) cairo_push_group_with_content (perf->cr, cairo_boilerplate_content (perf->target->content)); - (perf_func) (perf->cr, perf->size, perf->size); + perf_func (perf->cr, perf->size, perf->size, 1); + calibration0 = perf_func (perf->cr, perf->size, perf->size, 1); + loops = cairo_perf_ticks_per_second () / 100 / calibration0; + if (loops < 3) + loops = 3; + calibration = (calibration0 + perf_func (perf->cr, perf->size, perf->size, loops)) / (loops + 1); if (similar) cairo_pattern_destroy (cairo_pop_group (perf->cr)); + /* XXX + * Compute the number of loops required for the timing interval to + * be ~2 seconds. This helps to eliminate sampling variance due to + * timing and other systematic errors. However, it also hides + * synchronisation overhead as we attempt to process a large batch + * of identical operations in a single shot. This can be considered + * both good and bad... It would be good to perform a more rigorous + * analysis of the synchronisation overhead, that is to estimate + * the time for loop=0. + */ + loops = 2 * cairo_perf_ticks_per_second () / calibration; + if (loops < 10) + loops = 10; + low_std_dev_count = 0; for (i =0; i < perf->iterations; i++) { cairo_perf_yield (); if (similar) cairo_push_group_with_content (perf->cr, cairo_boilerplate_content (perf->target->content)); - times[i] = (perf_func) (perf->cr, perf->size, perf->size); + times[i] = perf_func (perf->cr, perf->size, perf->size, loops) / loops; if (similar) cairo_pattern_destroy (cairo_pop_group (perf->cr)); @@ -279,11 +301,12 @@ cairo_perf_run (cairo_perf_t *perf, if (perf->summary) { _cairo_stats_compute (&stats, times, i); fprintf (perf->summary, - "%10lld %#8.3f %#8.3f %#5.2f%% %3d\n", + "%10lld %#8.3f %#8.3f %#5.2f%% %3d %10lld\n", (long long) stats.min_ticks, (stats.min_ticks * 1000.0) / cairo_perf_ticks_per_second (), (stats.median_ticks * 1000.0) / cairo_perf_ticks_per_second (), - stats.std_dev * 100.0, stats.iterations); + stats.std_dev * 100.0, stats.iterations, + (long long) (calibration0 - stats.min_ticks)); fflush (perf->summary); } diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h index b6c502c6..139de8e5 100644 --- a/perf/cairo-perf.h +++ b/perf/cairo-perf.h @@ -94,7 +94,7 @@ typedef struct _cairo_perf { } cairo_perf_t; typedef cairo_perf_ticks_t -(*cairo_perf_func_t) (cairo_t *cr, int width, int height); +(*cairo_perf_func_t) (cairo_t *cr, int width, int height, int loops); cairo_bool_t cairo_perf_can_run (cairo_perf_t *perf, diff --git a/perf/composite-checker.c b/perf/composite-checker.c index e978990a..301006f9 100644 --- a/perf/composite-checker.c +++ b/perf/composite-checker.c @@ -50,7 +50,8 @@ static cairo_pattern_t *src_pattern = NULL; static cairo_perf_ticks_t do_composite_checker (cairo_t *cr, int width, - int height) + int height, + int loops) { /* Compute zoom so that the src_pattern covers the whole output image. */ double xscale = width / (double) SRC_SIZE; @@ -58,16 +59,17 @@ do_composite_checker (cairo_t *cr, cairo_perf_timer_start (); - cairo_identity_matrix (cr); + while (loops--) { + /* Fill the surface with our background. */ + cairo_identity_matrix (cr); + cairo_set_source (cr, checkerboard); + cairo_paint (cr); - /* Fill the surface with our background. */ - cairo_set_source (cr, checkerboard); - cairo_paint (cr); - - /* Draw the scaled image on top. */ - cairo_scale (cr, xscale, yscale); - cairo_set_source (cr, src_pattern); - cairo_paint (cr); + /* Draw the scaled image on top. */ + cairo_scale (cr, xscale, yscale); + cairo_set_source (cr, src_pattern); + cairo_paint (cr); + } cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); diff --git a/perf/dragon.c b/perf/dragon.c index 1866c9ac..366b63c2 100644 --- a/perf/dragon.c +++ b/perf/dragon.c @@ -94,7 +94,7 @@ path (cairo_t *cr, int step, int dir, int iterations) } static cairo_perf_ticks_t -do_dragon (cairo_t *cr, int width, int height) +do_dragon (cairo_t *cr, int width, int height, int loops) { cairo_pattern_t *pattern; double cx, cy, r; @@ -104,54 +104,56 @@ do_dragon (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); - cairo_pattern_add_color_stop_rgb (pattern, 0., .0, .0, .0); - cairo_pattern_add_color_stop_rgb (pattern, 0.25, .5, .4, .4); - cairo_pattern_add_color_stop_rgb (pattern, .5, .8, .8, .9); - cairo_pattern_add_color_stop_rgb (pattern, 1., .9, .9, 1.); - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - cairo_paint (cr); - - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); - cairo_set_line_width (cr, 4.); - - cairo_move_to (cr, cx, cy); - path (cr, 12, 0, 2048); - pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); - cairo_pattern_add_color_stop_rgb (pattern, 0., 1., 1., 1.); - cairo_pattern_add_color_stop_rgb (pattern, 1., 0., 0., 0.); - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - cairo_stroke(cr); - - cairo_move_to (cr, cx, cy); - path (cr, 12, 1, 2048); - pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); - cairo_pattern_add_color_stop_rgb (pattern, 1., 1., 1., 0.); - cairo_pattern_add_color_stop_rgb (pattern, 0., 1., 0., 0.); - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - cairo_stroke(cr); - - cairo_move_to (cr, cx, cy); - path (cr, 12, 2, 2048); - pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); - cairo_pattern_add_color_stop_rgb (pattern, 1., 0., 1., 1.); - cairo_pattern_add_color_stop_rgb (pattern, 0., 0., 1., 0.); - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - cairo_stroke(cr); - - cairo_move_to (cr, cx, cy); - path (cr, 12, 3, 2048); - pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); - cairo_pattern_add_color_stop_rgb (pattern, 1., 1., 0., 1.); - cairo_pattern_add_color_stop_rgb (pattern, 0., 0., 0., 1.); - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); - cairo_stroke(cr); + while (loops--) { + pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); + cairo_pattern_add_color_stop_rgb (pattern, 0., .0, .0, .0); + cairo_pattern_add_color_stop_rgb (pattern, 0.25, .5, .4, .4); + cairo_pattern_add_color_stop_rgb (pattern, .5, .8, .8, .9); + cairo_pattern_add_color_stop_rgb (pattern, 1., .9, .9, 1.); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + cairo_paint (cr); + + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); + cairo_set_line_width (cr, 4.); + + cairo_move_to (cr, cx, cy); + path (cr, 12, 0, 2048); + pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); + cairo_pattern_add_color_stop_rgb (pattern, 0., 1., 1., 1.); + cairo_pattern_add_color_stop_rgb (pattern, 1., 0., 0., 0.); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + cairo_stroke(cr); + + cairo_move_to (cr, cx, cy); + path (cr, 12, 1, 2048); + pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); + cairo_pattern_add_color_stop_rgb (pattern, 1., 1., 1., 0.); + cairo_pattern_add_color_stop_rgb (pattern, 0., 1., 0., 0.); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + cairo_stroke(cr); + + cairo_move_to (cr, cx, cy); + path (cr, 12, 2, 2048); + pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); + cairo_pattern_add_color_stop_rgb (pattern, 1., 0., 1., 1.); + cairo_pattern_add_color_stop_rgb (pattern, 0., 0., 1., 0.); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + cairo_stroke(cr); + + cairo_move_to (cr, cx, cy); + path (cr, 12, 3, 2048); + pattern = cairo_pattern_create_radial (cx, cy, 0., cx, cy, r); + cairo_pattern_add_color_stop_rgb (pattern, 1., 1., 0., 1.); + cairo_pattern_add_color_stop_rgb (pattern, 0., 0., 0., 1.); + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + cairo_stroke(cr); + } cairo_perf_timer_stop (); @@ -159,7 +161,7 @@ do_dragon (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_dragon_solid (cairo_t *cr, int width, int height) +do_dragon_solid (cairo_t *cr, int width, int height, int loops) { double cx, cy, r; @@ -168,30 +170,32 @@ do_dragon_solid (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_paint (cr); + while (loops--) { + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_paint (cr); - cairo_set_line_width (cr, 4.); + cairo_set_line_width (cr, 4.); - cairo_move_to (cr, cx, cy); - path (cr, 12, 0, 2048); - cairo_set_source_rgb (cr, 1, 0, 0); - cairo_stroke(cr); + cairo_move_to (cr, cx, cy); + path (cr, 12, 0, 2048); + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_stroke(cr); - cairo_move_to (cr, cx, cy); - path (cr, 12, 1, 2048); - cairo_set_source_rgb (cr, 0, 1, 0); - cairo_stroke(cr); + cairo_move_to (cr, cx, cy); + path (cr, 12, 1, 2048); + cairo_set_source_rgb (cr, 0, 1, 0); + cairo_stroke(cr); - cairo_move_to (cr, cx, cy); - path (cr, 12, 2, 2048); - cairo_set_source_rgb (cr, 0, 0, 1); - cairo_stroke(cr); + cairo_move_to (cr, cx, cy); + path (cr, 12, 2, 2048); + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_stroke(cr); - cairo_move_to (cr, cx, cy); - path (cr, 12, 3, 2048); - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_stroke(cr); + cairo_move_to (cr, cx, cy); + path (cr, 12, 3, 2048); + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_stroke(cr); + } cairo_perf_timer_stop (); diff --git a/perf/fill.c b/perf/fill.c index 0bad3cd9..453f9a42 100644 --- a/perf/fill.c +++ b/perf/fill.c @@ -26,7 +26,7 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_fill (cairo_t *cr, int width, int height) +do_fill (cairo_t *cr, int width, int height, int loops) { cairo_arc (cr, width/2.0, height/2.0, @@ -35,15 +35,18 @@ do_fill (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_fill (cr); + 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_fill_annuli (cairo_t *cr, int width, int height) +do_fill_annuli (cairo_t *cr, int width, int height, int loops) { cairo_new_sub_path (cr); cairo_arc (cr, @@ -71,15 +74,18 @@ do_fill_annuli (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_fill (cr); + 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_fill_eo_noaa (cairo_t *cr, int width, int height) +do_fill_eo_noaa (cairo_t *cr, int width, int height, int loops) { cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); @@ -91,10 +97,13 @@ do_fill_eo_noaa (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_fill (cr); + while (loops--) + cairo_fill_preserve (cr); cairo_perf_timer_stop (); + cairo_new_path (cr); + return cairo_perf_timer_elapsed (); } diff --git a/perf/glyphs.c b/perf/glyphs.c index fdd4d97a..bead68c4 100644 --- a/perf/glyphs.c +++ b/perf/glyphs.c @@ -28,7 +28,7 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_glyphs (cairo_t *cr, int width, int height) +do_glyphs (cairo_t *cr, int width, int height, int loops) { const char text[] = "the jay, pig, fox, zebra and my wolves quack"; cairo_scaled_font_t *scaled_font; @@ -61,22 +61,24 @@ do_glyphs (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - do { - x = 0; + while (loops--) { do { - for (n = 0; n < num_glyphs; n++) { - glyphs_copy[n] = glyphs[n]; - glyphs_copy[n].x += x; - glyphs_copy[n].y += y; - } - cairo_show_glyphs (cr, glyphs_copy, num_glyphs); - if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) - goto out; + x = 0; + do { + for (n = 0; n < num_glyphs; n++) { + glyphs_copy[n] = glyphs[n]; + glyphs_copy[n].x += x; + glyphs_copy[n].y += y; + } + cairo_show_glyphs (cr, glyphs_copy, num_glyphs); + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) + goto out; - x += extents.width; - } while (x < width); - y += extents.height; - } while (y < height); + x += extents.width; + } while (x < width); + y += extents.height; + } while (y < height); + } out: cairo_perf_timer_stop (); diff --git a/perf/intersections.c b/perf/intersections.c index 347c4a53..f35e0903 100644 --- a/perf/intersections.c +++ b/perf/intersections.c @@ -40,7 +40,8 @@ uniform_random (double minval, double maxval) } static cairo_perf_ticks_t -draw_random (cairo_t *cr, cairo_fill_rule_t fill_rule, int width, int height) +draw_random (cairo_t *cr, cairo_fill_rule_t fill_rule, + int width, int height, int loops) { int i; double x[NUM_SEGMENTS]; @@ -60,16 +61,14 @@ draw_random (cairo_t *cr, cairo_fill_rule_t fill_rule, int width, int height) cairo_set_fill_rule (cr, fill_rule); cairo_set_source_rgb (cr, 1, 0, 0); - cairo_perf_timer_start (); { + cairo_move_to (cr, 0, 0); + for (i = 0; i < NUM_SEGMENTS; i++) + cairo_line_to (cr, x[i], y[i]); + cairo_close_path (cr); - cairo_move_to (cr, 0, 0); - for (i = 0; i < NUM_SEGMENTS; i++) { - cairo_line_to (cr, x[i], y[i]); - } - cairo_close_path (cr); - - cairo_fill (cr); - } + cairo_perf_timer_start (); + while (loops--) + cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_restore (cr); @@ -78,15 +77,15 @@ draw_random (cairo_t *cr, cairo_fill_rule_t fill_rule, int width, int height) } static cairo_perf_ticks_t -random_eo (cairo_t *cr, int width, int height) +random_eo (cairo_t *cr, int width, int height, int loops) { - return draw_random (cr, CAIRO_FILL_RULE_EVEN_ODD, width, height); + return draw_random (cr, CAIRO_FILL_RULE_EVEN_ODD, width, height, loops); } static cairo_perf_ticks_t -random_nz (cairo_t *cr, int width, int height) +random_nz (cairo_t *cr, int width, int height, int loops) { - return draw_random (cr, CAIRO_FILL_RULE_WINDING, width, height); + return draw_random (cr, CAIRO_FILL_RULE_WINDING, width, height, loops); } void diff --git a/perf/long-dashed-lines.c b/perf/long-dashed-lines.c index 3520a197..96e6486c 100644 --- a/perf/long-dashed-lines.c +++ b/perf/long-dashed-lines.c @@ -28,7 +28,7 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_long_dashed_lines (cairo_t *cr, int width, int height) +do_long_dashed_lines (cairo_t *cr, int width, int height, int loops) { double dash[2] = { 2.0, 2.0 }; int i; @@ -40,8 +40,6 @@ do_long_dashed_lines (cairo_t *cr, int width, int height) cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); cairo_set_dash (cr, dash, 2, 0.0); - cairo_perf_timer_start (); - cairo_new_path (cr); cairo_set_line_width (cr, 1.0); @@ -51,7 +49,10 @@ do_long_dashed_lines (cairo_t *cr, int width, int height) cairo_line_to (cr, width, y0); } - cairo_stroke (cr); + cairo_perf_timer_start (); + + while (loops--) + cairo_stroke_preserve (cr); cairo_perf_timer_stop (); diff --git a/perf/long-lines.c b/perf/long-lines.c index 67f698a0..124c4f2b 100644 --- a/perf/long-lines.c +++ b/perf/long-lines.c @@ -43,7 +43,7 @@ typedef enum { #define LONG_FACTOR 50.0 static cairo_perf_ticks_t -do_long_lines (cairo_t *cr, int width, int height, long_lines_crop_t crop) +do_long_lines (cairo_t *cr, int width, int height, int loops, long_lines_crop_t crop) { int i; double x, y, dx, dy, min_x, min_y, max_x, max_y; @@ -72,32 +72,34 @@ do_long_lines (cairo_t *cr, int width, int height, long_lines_crop_t crop) cairo_perf_timer_start (); - for (i = 0; i <= NUM_LINES; i++) { - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, x, min_y); - if ((crop & LONG_LINES_ONCE) == 0) + while (loops--) { + for (i = 0; i <= NUM_LINES; i++) { + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, x, min_y); + if ((crop & LONG_LINES_ONCE) == 0) + cairo_stroke (cr); + + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, x, max_y); + if ((crop & LONG_LINES_ONCE) == 0) + cairo_stroke (cr); + + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, min_x, y); + if ((crop & LONG_LINES_ONCE) == 0) + cairo_stroke (cr); + + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, max_x, y); + if ((crop & LONG_LINES_ONCE) == 0) + cairo_stroke (cr); + + x += dx; + y += dy; + } + if (crop & LONG_LINES_ONCE) cairo_stroke (cr); - - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, x, max_y); - if ((crop & LONG_LINES_ONCE) == 0) - cairo_stroke (cr); - - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, min_x, y); - if ((crop & LONG_LINES_ONCE) == 0) - cairo_stroke (cr); - - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, max_x, y); - if ((crop & LONG_LINES_ONCE) == 0) - cairo_stroke (cr); - - x += dx; - y += dy; } - if (crop & LONG_LINES_ONCE) - cairo_stroke (cr); cairo_perf_timer_stop (); @@ -107,27 +109,27 @@ do_long_lines (cairo_t *cr, int width, int height, long_lines_crop_t crop) } static cairo_perf_ticks_t -long_lines_uncropped (cairo_t *cr, int width, int height) +long_lines_uncropped (cairo_t *cr, int width, int height, int loops) { - return do_long_lines (cr, width, height, 0); + return do_long_lines (cr, width, height, loops, 0); } static cairo_perf_ticks_t -long_lines_uncropped_once (cairo_t *cr, int width, int height) +long_lines_uncropped_once (cairo_t *cr, int width, int height, int loops) { - return do_long_lines (cr, width, height, LONG_LINES_ONCE); + return do_long_lines (cr, width, height, loops, LONG_LINES_ONCE); } static cairo_perf_ticks_t -long_lines_cropped (cairo_t *cr, int width, int height) +long_lines_cropped (cairo_t *cr, int width, int height, int loops) { - return do_long_lines (cr, width, height, LONG_LINES_CROPPED); + return do_long_lines (cr, width, height, loops, LONG_LINES_CROPPED); } static cairo_perf_ticks_t -long_lines_cropped_once (cairo_t *cr, int width, int height) +long_lines_cropped_once (cairo_t *cr, int width, int height, int loops) { - return do_long_lines (cr, width, height, LONG_LINES_CROPPED | LONG_LINES_ONCE); + return do_long_lines (cr, width, height, loops, LONG_LINES_CROPPED | LONG_LINES_ONCE); } void diff --git a/perf/mask.c b/perf/mask.c index 4dc305ef..55dc20a5 100644 --- a/perf/mask.c +++ b/perf/mask.c @@ -28,7 +28,7 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_mask_solid (cairo_t *cr, int width, int height) +do_mask_solid (cairo_t *cr, int width, int height, int loops) { cairo_pattern_t *mask; @@ -36,7 +36,8 @@ do_mask_solid (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -70,7 +71,7 @@ init_surface (cairo_surface_t *surface, int width, int height) } static cairo_perf_ticks_t -do_mask_image (cairo_t *cr, int width, int height) +do_mask_image (cairo_t *cr, int width, int height, int loops) { cairo_surface_t *surface; cairo_pattern_t *mask; @@ -83,7 +84,8 @@ do_mask_image (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -93,7 +95,7 @@ do_mask_image (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_mask_image_half (cairo_t *cr, int width, int height) +do_mask_image_half (cairo_t *cr, int width, int height, int loops) { cairo_surface_t *surface; cairo_pattern_t *mask; @@ -109,7 +111,8 @@ do_mask_image_half (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -119,7 +122,7 @@ do_mask_image_half (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_mask_image_double (cairo_t *cr, int width, int height) +do_mask_image_double (cairo_t *cr, int width, int height, int loops) { cairo_surface_t *surface; cairo_pattern_t *mask; @@ -135,7 +138,8 @@ do_mask_image_double (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -145,7 +149,7 @@ do_mask_image_double (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_mask_similar (cairo_t *cr, int width, int height) +do_mask_similar (cairo_t *cr, int width, int height, int loops) { cairo_surface_t *surface; cairo_pattern_t *mask; @@ -159,7 +163,8 @@ do_mask_similar (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -169,7 +174,7 @@ do_mask_similar (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_mask_similar_half (cairo_t *cr, int width, int height) +do_mask_similar_half (cairo_t *cr, int width, int height, int loops) { cairo_surface_t *surface; cairo_pattern_t *mask; @@ -186,7 +191,8 @@ do_mask_similar_half (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -196,7 +202,7 @@ do_mask_similar_half (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_mask_similar_double (cairo_t *cr, int width, int height) +do_mask_similar_double (cairo_t *cr, int width, int height, int loops) { cairo_surface_t *surface; cairo_pattern_t *mask; @@ -213,7 +219,8 @@ do_mask_similar_double (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -223,7 +230,7 @@ do_mask_similar_double (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_mask_linear (cairo_t *cr, int width, int height) +do_mask_linear (cairo_t *cr, int width, int height, int loops) { cairo_pattern_t *mask; @@ -233,7 +240,8 @@ do_mask_linear (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); @@ -243,7 +251,7 @@ do_mask_linear (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_mask_radial (cairo_t *cr, int width, int height) +do_mask_radial (cairo_t *cr, int width, int height, int loops) { cairo_pattern_t *mask; @@ -254,7 +262,8 @@ do_mask_radial (cairo_t *cr, int width, int height) cairo_perf_timer_start (); - cairo_mask (cr, mask); + while (loops--) + cairo_mask (cr, mask); cairo_perf_timer_stop (); diff --git a/perf/mosaic.c b/perf/mosaic.c index bab62765..715dffb9 100644 --- a/perf/mosaic.c +++ b/perf/mosaic.c @@ -93,7 +93,7 @@ mosaic_next_path (cairo_t *cr, struct mosaic_region_iter *iter) } static cairo_perf_ticks_t -mosaic_perform(cairo_t *cr, unsigned flags, int width, int height) +mosaic_perform(cairo_t *cr, unsigned flags, int width, int height, int loops) { struct mosaic_region_iter iter; @@ -116,17 +116,19 @@ mosaic_perform(cairo_t *cr, unsigned flags, int width, int height) /* Iterate over all closed regions in the mosaic filling or * tessellating them as dictated by the flags. */ - mosaic_region_iter_init (&iter, flags & MOSAIC_CURVE_TO); cairo_perf_timer_start (); - while (mosaic_next_path (cr, &iter)) { - if (flags & MOSAIC_FILL) { - cairo_fill (cr); - } - else { - double x, y; - cairo_get_current_point (cr, &x, &y); - cairo_in_fill (cr, x, y); + while (loops--) { + mosaic_region_iter_init (&iter, flags & MOSAIC_CURVE_TO); + while (mosaic_next_path (cr, &iter)) { + if (flags & MOSAIC_FILL) { + cairo_fill (cr); + } + else { + double x, y; + cairo_get_current_point (cr, &x, &y); + cairo_in_fill (cr, x, y); + } } } cairo_perf_timer_stop (); @@ -135,27 +137,27 @@ mosaic_perform(cairo_t *cr, unsigned flags, int width, int height) } static cairo_perf_ticks_t -mosaic_fill_curves (cairo_t *cr, int width, int height) +mosaic_fill_curves (cairo_t *cr, int width, int height, int loops) { - return mosaic_perform (cr, MOSAIC_FILL | MOSAIC_CURVE_TO, width, height); + return mosaic_perform (cr, MOSAIC_FILL | MOSAIC_CURVE_TO, width, height, loops); } static cairo_perf_ticks_t -mosaic_fill_lines (cairo_t *cr, int width, int height) +mosaic_fill_lines (cairo_t *cr, int width, int height, int loops) { - return mosaic_perform (cr, MOSAIC_FILL | MOSAIC_LINE_TO, width, height); + return mosaic_perform (cr, MOSAIC_FILL | MOSAIC_LINE_TO, width, height, loops); } static cairo_perf_ticks_t -mosaic_tessellate_lines (cairo_t *cr, int width, int height) +mosaic_tessellate_lines (cairo_t *cr, int width, int height, int loops) { - return mosaic_perform (cr, MOSAIC_TESSELLATE | MOSAIC_LINE_TO, width, height); + return mosaic_perform (cr, MOSAIC_TESSELLATE | MOSAIC_LINE_TO, width, height, loops); } static cairo_perf_ticks_t -mosaic_tessellate_curves (cairo_t *cr, int width, int height) +mosaic_tessellate_curves (cairo_t *cr, int width, int height, int loops) { - return mosaic_perform (cr, MOSAIC_TESSELLATE | MOSAIC_CURVE_TO, width, height); + return mosaic_perform (cr, MOSAIC_TESSELLATE | MOSAIC_CURVE_TO, width, height, loops); } void diff --git a/perf/paint-with-alpha.c b/perf/paint-with-alpha.c index 6ffe8bb1..cef353d5 100644 --- a/perf/paint-with-alpha.c +++ b/perf/paint-with-alpha.c @@ -26,11 +26,12 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_paint_with_alpha (cairo_t *cr, int width, int height) +do_paint_with_alpha (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); - cairo_paint_with_alpha (cr, 0.5); + while (loops--) + cairo_paint_with_alpha (cr, 0.5); cairo_perf_timer_stop (); diff --git a/perf/paint.c b/perf/paint.c index a60d132b..ac7c724e 100644 --- a/perf/paint.c +++ b/perf/paint.c @@ -26,11 +26,12 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_paint (cairo_t *cr, int width, int height) +do_paint (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); - cairo_paint (cr); + while (loops--) + cairo_paint (cr); cairo_perf_timer_stop (); diff --git a/perf/pattern_create_radial.c b/perf/pattern_create_radial.c index b9081515..26dc713c 100644 --- a/perf/pattern_create_radial.c +++ b/perf/pattern_create_radial.c @@ -56,20 +56,22 @@ generate_double_in_range (double min, double max) } static cairo_perf_ticks_t -do_pattern_create_radial (cairo_t *cr, int width, int height) +do_pattern_create_radial (cairo_t *cr, int width, int height, int loops) { - int i; - cairo_pattern_t *pattern; - cairo_perf_timer_start (); - for (i = 0; i < RADIALS_COUNT; i++) - { - pattern = cairo_pattern_create_radial (radials[i].cx0, radials[i].cy0, - radials[i].radius0, - radials[i].cx1, radials[i].cy1, - radials[i].radius1); - cairo_pattern_destroy (pattern); + while (loops--) { + cairo_pattern_t *pattern; + int i; + + for (i = 0; i < RADIALS_COUNT; i++) { + pattern = + cairo_pattern_create_radial (radials[i].cx0, radials[i].cy0, + radials[i].radius0, + radials[i].cx1, radials[i].cy1, + radials[i].radius1); + cairo_pattern_destroy (pattern); + } } cairo_perf_timer_stop (); diff --git a/perf/pythagoras-tree.c b/perf/pythagoras-tree.c index a1cce5c0..bf37f5f3 100644 --- a/perf/pythagoras-tree.c +++ b/perf/pythagoras-tree.c @@ -58,21 +58,23 @@ add_rectangle (cairo_t *cr, double size) } static cairo_perf_ticks_t -do_pythagoras_tree (cairo_t *cr, int width, int height) +do_pythagoras_tree (cairo_t *cr, int width, int height, int loops) { double size = 128; cairo_perf_timer_start (); - cairo_save (cr); - cairo_translate (cr, 0, height); - cairo_scale (cr, 1, -1); + while (loops--) { + cairo_save (cr); + cairo_translate (cr, 0, height); + cairo_scale (cr, 1, -1); - cairo_move_to (cr, width/2, size/2); - add_rectangle (cr, size); - cairo_set_source_rgb (cr, 0., 0., 0.); - cairo_fill (cr); - cairo_restore (cr); + cairo_move_to (cr, width/2, size/2); + add_rectangle (cr, size); + cairo_set_source_rgb (cr, 0., 0., 0.); + cairo_fill (cr); + cairo_restore (cr); + } cairo_perf_timer_stop (); diff --git a/perf/rectangles.c b/perf/rectangles.c index c224968f..53b908ec 100644 --- a/perf/rectangles.c +++ b/perf/rectangles.c @@ -32,8 +32,7 @@ #define RECTANGLE_COUNT (1000) -static struct -{ +static struct { double x; double y; double width; @@ -41,17 +40,18 @@ static struct } rects[RECTANGLE_COUNT]; static cairo_perf_ticks_t -do_rectangles (cairo_t *cr, int width, int height) +do_rectangles (cairo_t *cr, int width, int height, int loops) { int i; cairo_perf_timer_start (); - for (i = 0; i < RECTANGLE_COUNT; i++) - { - cairo_rectangle (cr, rects[i].x, rects[i].y, - rects[i].width, rects[i].height); - cairo_fill (cr); + while (loops--) { + for (i = 0; i < RECTANGLE_COUNT; i++) { + cairo_rectangle (cr, rects[i].x, rects[i].y, + rects[i].width, rects[i].height); + cairo_fill (cr); + } } cairo_perf_timer_stop (); @@ -60,18 +60,20 @@ do_rectangles (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_rectangles_once (cairo_t *cr, int width, int height) +do_rectangles_once (cairo_t *cr, int width, int height, int loops) { int i; cairo_perf_timer_start (); - for (i = 0; i < RECTANGLE_COUNT; i++) - { - cairo_rectangle (cr, rects[i].x, rects[i].y, - rects[i].width, rects[i].height); + while (loops--) { + for (i = 0; i < RECTANGLE_COUNT; i++) { + cairo_rectangle (cr, rects[i].x, rects[i].y, + rects[i].width, rects[i].height); + } + + cairo_fill (cr); } - cairo_fill (cr); cairo_perf_timer_stop (); @@ -79,12 +81,14 @@ do_rectangles_once (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_rectangle (cairo_t *cr, int width, int height) +do_rectangle (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); - cairo_rectangle (cr, 0, 0, width, height); - cairo_fill (cr); + while (loops--) { + cairo_rectangle (cr, 0, 0, width, height); + cairo_fill (cr); + } cairo_perf_timer_stop (); diff --git a/perf/rounded-rectangles.c b/perf/rounded-rectangles.c index 25133f38..2cd89a8b 100644 --- a/perf/rounded-rectangles.c +++ b/perf/rounded-rectangles.c @@ -61,12 +61,14 @@ rounded_rectangle (cairo_t *cr, } static cairo_perf_ticks_t -do_rectangle (cairo_t *cr, int width, int height) +do_rectangle (cairo_t *cr, int width, int height, int loops) { cairo_perf_timer_start (); - rounded_rectangle (cr, 0, 0, width, height, 3.0); - cairo_fill (cr); + while (loops--) { + rounded_rectangle (cr, 0, 0, width, height, 3.0); + cairo_fill (cr); + } cairo_perf_timer_stop (); @@ -74,18 +76,42 @@ do_rectangle (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -do_rectangles (cairo_t *cr, int width, int height) +do_rectangles (cairo_t *cr, int width, int height, int loops) { int i; cairo_perf_timer_start (); - for (i = 0; i < RECTANGLE_COUNT; i++) { - rounded_rectangle (cr, - rects[i].x, rects[i].y, - rects[i].width, rects[i].height, - 3.0); - cairo_fill (cr); + while (loops--) { + for (i = 0; i < RECTANGLE_COUNT; i++) { + rounded_rectangle (cr, + rects[i].x, rects[i].y, + rects[i].width, rects[i].height, + 3.0); + cairo_fill (cr); + } + } + + cairo_perf_timer_stop (); + + return cairo_perf_timer_elapsed (); +} + +static cairo_perf_ticks_t +do_rectangles_once (cairo_t *cr, int width, int height, int loops) +{ + int i; + + cairo_perf_timer_start (); + + while (loops--) { + for (i = 0; i < RECTANGLE_COUNT; i++) { + rounded_rectangle (cr, + rects[i].x, rects[i].y, + rects[i].width, rects[i].height, + 3.0); + } + cairo_fill (cr); } cairo_perf_timer_stop (); @@ -111,4 +137,5 @@ rounded_rectangles (cairo_perf_t *perf, cairo_t *cr, int width, int height) MODE (perf, "one-rounded-rectangle", do_rectangle); MODE (perf, "rounded-rectangles", do_rectangles); + MODE (perf, "rounded-rectangles-once", do_rectangles_once); } diff --git a/perf/spiral.c b/perf/spiral.c index fb2af61d..2a4e568a 100644 --- a/perf/spiral.c +++ b/perf/spiral.c @@ -44,7 +44,7 @@ draw_spiral (cairo_t *cr, cairo_fill_rule_t fill_rule, align_t align, close_t close, - int width, int height) + int width, int height, int loops) { int i; int n=0; @@ -89,16 +89,15 @@ draw_spiral (cairo_t *cr, cairo_set_fill_rule (cr, fill_rule); cairo_set_source_rgb (cr, 1, 0, 0); - cairo_perf_timer_start (); { - - cairo_move_to (cr, x[0], y[0]); - for (i = 1; i < n; i++) { - cairo_line_to (cr, x[i], y[i]); - } - cairo_close_path (cr); - - cairo_fill (cr); + cairo_move_to (cr, x[0], y[0]); + for (i = 1; i < n; i++) { + cairo_line_to (cr, x[i], y[i]); } + cairo_close_path (cr); + + cairo_perf_timer_start (); + while (loops--) + cairo_fill_preserve (cr); cairo_perf_timer_stop (); cairo_restore (cr); @@ -107,83 +106,83 @@ draw_spiral (cairo_t *cr, } static cairo_perf_ticks_t -draw_spiral_eo_pa_re (cairo_t *cr, int width, int height) +draw_spiral_eo_pa_re (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_EVEN_ODD, PIXALIGN, RECTCLOSE, - width, height); + width, height, loops); } static cairo_perf_ticks_t -draw_spiral_nz_pa_re (cairo_t *cr, int width, int height) +draw_spiral_nz_pa_re (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_WINDING, PIXALIGN, RECTCLOSE, - width, height); + width, height, loops); } static cairo_perf_ticks_t -draw_spiral_eo_na_re (cairo_t *cr, int width, int height) +draw_spiral_eo_na_re (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_EVEN_ODD, NONALIGN, RECTCLOSE, - width, height); + width, height, loops); } static cairo_perf_ticks_t -draw_spiral_nz_na_re (cairo_t *cr, int width, int height) +draw_spiral_nz_na_re (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_WINDING, NONALIGN, RECTCLOSE, - width, height); + width, height, loops); } static cairo_perf_ticks_t -draw_spiral_eo_pa_di (cairo_t *cr, int width, int height) +draw_spiral_eo_pa_di (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_EVEN_ODD, PIXALIGN, DIAGCLOSE, - width, height); + width, height, loops); } static cairo_perf_ticks_t -draw_spiral_nz_pa_di (cairo_t *cr, int width, int height) +draw_spiral_nz_pa_di (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_WINDING, PIXALIGN, DIAGCLOSE, - width, height); + width, height, loops); } static cairo_perf_ticks_t -draw_spiral_eo_na_di (cairo_t *cr, int width, int height) +draw_spiral_eo_na_di (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_EVEN_ODD, NONALIGN, DIAGCLOSE, - width, height); + width, height, loops); } static cairo_perf_ticks_t -draw_spiral_nz_na_di (cairo_t *cr, int width, int height) +draw_spiral_nz_na_di (cairo_t *cr, int width, int height, int loops) { return draw_spiral (cr, CAIRO_FILL_RULE_WINDING, NONALIGN, DIAGCLOSE, - width, height); + width, height, loops); } void diff --git a/perf/stroke.c b/perf/stroke.c index b3602261..81ba8f27 100644 --- a/perf/stroke.c +++ b/perf/stroke.c @@ -26,7 +26,7 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_stroke (cairo_t *cr, int width, int height) +do_stroke (cairo_t *cr, int width, int height, int loops) { cairo_arc (cr, width/2.0, height/2.0, @@ -34,13 +34,17 @@ do_stroke (cairo_t *cr, int width, int height) 0, 2 * M_PI); cairo_close_path (cr); + cairo_set_line_width (cr, width/5.0); + cairo_perf_timer_start (); - cairo_set_line_width (cr, width/5.0); - cairo_stroke (cr); + while (loops--) + cairo_stroke_preserve (cr); cairo_perf_timer_stop (); + cairo_new_path (cr); + return cairo_perf_timer_elapsed (); } @@ -57,7 +61,7 @@ rounded_rectangle (cairo_t *cr, } static cairo_perf_ticks_t -do_strokes (cairo_t *cr, int width, int height) +do_strokes (cairo_t *cr, int width, int height, int loops) { /* a pair of overlapping rectangles */ rounded_rectangle (cr, @@ -65,17 +69,20 @@ do_strokes (cairo_t *cr, int width, int height) 10); rounded_rectangle (cr, width/2. - 10, height/2. - 10, - width - 2, height - 2, + width/2. - 2, height/2. - 2, 10); cairo_set_line_width (cr, 2.); cairo_perf_timer_start (); - cairo_stroke (cr); + while (loops--) + cairo_stroke_preserve (cr); cairo_perf_timer_stop (); + cairo_new_path (cr); + return cairo_perf_timer_elapsed (); } diff --git a/perf/subimage_copy.c b/perf/subimage_copy.c index 25b16cc2..9bec2fb0 100644 --- a/perf/subimage_copy.c +++ b/perf/subimage_copy.c @@ -35,17 +35,20 @@ */ static cairo_perf_ticks_t -do_subimage_copy (cairo_t *cr, int width, int height) +do_subimage_copy (cairo_t *cr, int width, int height, int loops) { cairo_rectangle (cr, 2, 2, 4, 4); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_perf_timer_start (); - cairo_fill (cr); + while (loops--) + cairo_fill_preserve (cr); cairo_perf_timer_stop (); + cairo_new_path (cr); + return cairo_perf_timer_elapsed (); } diff --git a/perf/tessellate.c b/perf/tessellate.c index 4af38411..1a4d978d 100644 --- a/perf/tessellate.c +++ b/perf/tessellate.c @@ -99,7 +99,7 @@ point_t points[300] = { }; static cairo_perf_ticks_t -do_tessellate (cairo_t *cr, int num_points) +do_tessellate (cairo_t *cr, int num_points, int loops) { int i; @@ -113,7 +113,8 @@ do_tessellate (cairo_t *cr, int num_points) * we'll have to be careful since cairo_in_fill might eventually * be optimized to have an implementation that doesn't necessarily * include tessellation. */ - cairo_in_fill (cr, 50, 50); + while (loops--) + cairo_in_fill (cr, 50, 50); cairo_perf_timer_stop (); @@ -123,21 +124,21 @@ do_tessellate (cairo_t *cr, int num_points) } static cairo_perf_ticks_t -tessellate_16 (cairo_t *cr, int width, int height) +tessellate_16 (cairo_t *cr, int width, int height, int loops) { - return do_tessellate (cr, 16); + return do_tessellate (cr, 16, loops); } static cairo_perf_ticks_t -tessellate_64 (cairo_t *cr, int width, int height) +tessellate_64 (cairo_t *cr, int width, int height, int loops) { - return do_tessellate (cr, 64); + return do_tessellate (cr, 64, loops); } static cairo_perf_ticks_t -tessellate_256 (cairo_t *cr, int width, int height) +tessellate_256 (cairo_t *cr, int width, int height, int loops) { - return do_tessellate (cr, 256); + return do_tessellate (cr, 256, loops); } void diff --git a/perf/text.c b/perf/text.c index 4448802a..9c512743 100644 --- a/perf/text.c +++ b/perf/text.c @@ -26,27 +26,30 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_text (cairo_t *cr, int width, int height) +do_text (cairo_t *cr, int width, int height, int loops) { const char text[] = "the jay, pig, fox, zebra and my wolves quack"; int len = strlen (text); double x, y; int i = 0, j = 0; + cairo_set_font_size (cr, 9); + cairo_perf_timer_start (); - cairo_set_font_size (cr, 9); - do { - cairo_move_to (cr, 0, j++ * 10); - cairo_show_text (cr, text + i); - cairo_get_current_point (cr, &x, &y); - while (x < width && cairo_status (cr) == CAIRO_STATUS_SUCCESS) { - cairo_show_text (cr, text); + while (loops--) { + do { + cairo_move_to (cr, 0, j++ * 10); + cairo_show_text (cr, text + i); cairo_get_current_point (cr, &x, &y); - } - if (++i >= len) - i = 0; - } while (y < height && cairo_status (cr) == CAIRO_STATUS_SUCCESS); + while (x < width && cairo_status (cr) == CAIRO_STATUS_SUCCESS) { + cairo_show_text (cr, text); + cairo_get_current_point (cr, &x, &y); + } + if (++i >= len) + i = 0; + } while (y < height && cairo_status (cr) == CAIRO_STATUS_SUCCESS); + } cairo_perf_timer_stop (); diff --git a/perf/twin.c b/perf/twin.c index f65cccf8..4dd06dd0 100644 --- a/perf/twin.c +++ b/perf/twin.c @@ -6,7 +6,8 @@ static cairo_perf_ticks_t do_twin (cairo_t *cr, int width, - int height) + int height, + int loops) { int i, j, h; unsigned char s[2] = {0, 0}; @@ -15,26 +16,28 @@ do_twin (cairo_t *cr, cairo_paint (cr); cairo_set_source_rgb (cr, 0, 0, 0); - cairo_perf_timer_start (); - cairo_select_font_face (cr, "@cairo:", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - h = 2; - for (i = 8; i < 48; i >= 24 ? i+=3 : i++) { - cairo_set_font_size (cr, i); - for (j = 33; j < 128; j++) { - if (j == 33 || (j == 80 && i > 24)) { - h += i + 2; - cairo_move_to (cr, 10, h); + cairo_perf_timer_start (); + + while (loops--) { + h = 2; + for (i = 8; i < 48; i >= 24 ? i+=3 : i++) { + cairo_set_font_size (cr, i); + for (j = 33; j < 128; j++) { + if (j == 33 || (j == 80 && i > 24)) { + h += i + 2; + cairo_move_to (cr, 10, h); + } + s[0] = j; + cairo_text_path (cr, (const char *) s); } - s[0] = j; - cairo_text_path (cr, (const char *) s); } + cairo_fill (cr); } - cairo_fill (cr); cairo_perf_timer_stop (); return cairo_perf_timer_elapsed (); diff --git a/perf/unaligned-clip.c b/perf/unaligned-clip.c index f379b61e..f532b556 100644 --- a/perf/unaligned-clip.c +++ b/perf/unaligned-clip.c @@ -29,33 +29,32 @@ #include "cairo-perf.h" static cairo_perf_ticks_t -do_unaligned_clip (cairo_t *cr, int width, int height) +do_unaligned_clip (cairo_t *cr, int width, int height, int loops) { - cairo_save (cr); - cairo_perf_timer_start (); - /* First a triangular clip that obviously isn't along device-pixel - * boundaries. */ - cairo_move_to (cr, 50, 50); - cairo_line_to (cr, 50, 90); - cairo_line_to (cr, 90, 90); - cairo_close_path (cr); - cairo_clip (cr); + while (loops--) { + /* First a triangular clip that obviously isn't along device-pixel + * boundaries. */ + cairo_move_to (cr, 50, 50); + cairo_line_to (cr, 50, 90); + cairo_line_to (cr, 90, 90); + cairo_close_path (cr); + cairo_clip (cr); - /* Then a rectangular clip that would be but for the non-integer - * scaling. */ - cairo_scale (cr, 1.1, 1.1); - cairo_rectangle (cr, 55, 55, 35, 35); - cairo_clip (cr); + /* Then a rectangular clip that would be but for the non-integer + * scaling. */ + cairo_scale (cr, 1.1, 1.1); + cairo_rectangle (cr, 55, 55, 35, 35); + cairo_clip (cr); - /* And paint something to force the clip to be evaluated. */ - cairo_paint (cr); + /* And paint something to force the clip to be evaluated. */ + cairo_paint (cr); + cairo_reset_clip (cr); + } cairo_perf_timer_stop (); - cairo_restore (cr); - return cairo_perf_timer_elapsed (); } diff --git a/perf/world-map.c b/perf/world-map.c index 5a53f308..265c8e31 100644 --- a/perf/world-map.c +++ b/perf/world-map.c @@ -49,52 +49,54 @@ typedef struct _wm_element { #include "world-map.h" static cairo_perf_ticks_t -do_world_map (cairo_t *cr, int width, int height) +do_world_map (cairo_t *cr, int width, int height, int loops) { const wm_element_t *e; double cx, cy; - cairo_perf_timer_start (); + cairo_set_line_width (cr, 0.2); - cairo_set_source_rgb (cr, .68, .85, .90); /* lightblue */ - cairo_rectangle (cr, 0, 0, 800, 400); - cairo_fill (cr); + cairo_perf_timer_start (); - cairo_set_line_width (cr, 0.2); + while (loops--) { + cairo_set_source_rgb (cr, .68, .85, .90); /* lightblue */ + cairo_rectangle (cr, 0, 0, 800, 400); + cairo_fill (cr); - e = &countries[0]; - while (1) { - switch (e->type) { - case WM_NEW_PATH: - case WM_END: - cairo_set_source_rgb (cr, .75, .75, .75); /* silver */ - cairo_fill_preserve (cr); - cairo_set_source_rgb (cr, .50, .50, .50); /* gray */ - cairo_stroke (cr); - cairo_move_to (cr, e->x, e->y); - break; - case WM_MOVE_TO: - cairo_close_path (cr); - cairo_move_to (cr, e->x, e->y); - break; - case WM_LINE_TO: - cairo_line_to (cr, e->x, e->y); - break; - case WM_HLINE_TO: - cairo_get_current_point (cr, &cx, &cy); - cairo_line_to (cr, e->x, cy); - break; - case WM_VLINE_TO: - cairo_get_current_point (cr, &cx, &cy); - cairo_line_to (cr, cx, e->y); - break; - case WM_REL_LINE_TO: - cairo_rel_line_to (cr, e->x, e->y); - break; + e = &countries[0]; + while (1) { + switch (e->type) { + case WM_NEW_PATH: + case WM_END: + cairo_set_source_rgb (cr, .75, .75, .75); /* silver */ + cairo_fill_preserve (cr); + cairo_set_source_rgb (cr, .50, .50, .50); /* gray */ + cairo_stroke (cr); + cairo_move_to (cr, e->x, e->y); + break; + case WM_MOVE_TO: + cairo_close_path (cr); + cairo_move_to (cr, e->x, e->y); + break; + case WM_LINE_TO: + cairo_line_to (cr, e->x, e->y); + break; + case WM_HLINE_TO: + cairo_get_current_point (cr, &cx, &cy); + cairo_line_to (cr, e->x, cy); + break; + case WM_VLINE_TO: + cairo_get_current_point (cr, &cx, &cy); + cairo_line_to (cr, cx, e->y); + break; + case WM_REL_LINE_TO: + cairo_rel_line_to (cr, e->x, e->y); + break; + } + if (e->type == WM_END) + break; + e++; } - if (e->type == WM_END) - break; - e++; } cairo_perf_timer_stop (); diff --git a/perf/zrusin.c b/perf/zrusin.c index 9393932b..d57c7c4b 100644 --- a/perf/zrusin.c +++ b/perf/zrusin.c @@ -45,7 +45,7 @@ zrusin_another_path (cairo_t *cr) } static cairo_perf_ticks_t -zrusin_another_tessellate (cairo_t *cr, int width, int height) +zrusin_another_tessellate (cairo_t *cr, int width, int height, int loops) { zrusin_another_path (cr); @@ -56,7 +56,8 @@ zrusin_another_tessellate (cairo_t *cr, int width, int height) * we'll have to be careful since cairo_in_fill might eventually * be optimized to have an implementation that doesn't necessarily * include tessellation. */ - cairo_in_fill (cr, 50, 50); + while (loops--) + cairo_in_fill (cr, 50, 50); cairo_perf_timer_stop (); @@ -66,14 +67,15 @@ zrusin_another_tessellate (cairo_t *cr, int width, int height) } static cairo_perf_ticks_t -zrusin_another_fill (cairo_t *cr, int width, int height) +zrusin_another_fill (cairo_t *cr, int width, int height, int loops) { zrusin_another_path (cr); cairo_set_source_rgb (cr, 0.0, 0.0, 0.8); /* blue */ cairo_perf_timer_start (); - cairo_fill (cr); + while (loops--) + cairo_fill_preserve (cr); cairo_perf_timer_stop (); |