2006-09-14 12:59:31 -07:00
|
|
|
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
|
2006-08-31 07:19:05 -07:00
|
|
|
/*
|
2006-08-31 10:39:24 -07:00
|
|
|
* Copyright © 2006 Mozilla Corporation
|
2006-08-31 07:19:05 -07:00
|
|
|
* Copyright © 2006 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
* appear in supporting documentation, and that the name of
|
2006-08-31 10:39:24 -07:00
|
|
|
* the authors not be used in advertising or publicity pertaining to
|
2006-08-31 07:19:05 -07:00
|
|
|
* distribution of the software without specific, written prior
|
2006-08-31 10:39:24 -07:00
|
|
|
* permission. The authors make no representations about the
|
2006-08-31 07:19:05 -07:00
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
2006-08-31 10:39:24 -07:00
|
|
|
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
2006-08-31 07:19:05 -07:00
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
2006-08-31 10:39:24 -07:00
|
|
|
* FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
|
2006-08-31 07:19:05 -07:00
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
2006-08-31 10:39:24 -07:00
|
|
|
* Authors: Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
|
* Carl Worth <cworth@cworth.org>
|
2006-08-31 07:19:05 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cairo-perf.h"
|
|
|
|
|
|
2006-08-31 17:43:40 -07:00
|
|
|
int cairo_perf_iterations = 100;
|
2006-08-31 10:39:24 -07:00
|
|
|
|
2006-08-31 07:19:05 -07:00
|
|
|
typedef struct _cairo_perf {
|
|
|
|
|
const char *name;
|
|
|
|
|
cairo_perf_func_t run;
|
|
|
|
|
unsigned int min_size;
|
|
|
|
|
unsigned int max_size;
|
|
|
|
|
} cairo_perf_t;
|
|
|
|
|
|
2006-08-31 11:51:28 -07:00
|
|
|
cairo_perf_t perfs[];
|
2006-08-31 07:19:05 -07:00
|
|
|
|
2006-08-31 08:53:58 -07:00
|
|
|
/* Some targets just aren't that interesting for performance testing,
|
|
|
|
|
* (not least because many of these surface types use a meta-surface
|
|
|
|
|
* and as such defer the "real" rendering to later, so our timing
|
|
|
|
|
* loops wouldn't count the real work, just the recording by the
|
|
|
|
|
* meta-surface. */
|
|
|
|
|
static cairo_bool_t
|
2006-09-09 14:55:57 -07:00
|
|
|
target_is_measurable (cairo_boilerplate_target_t *target)
|
2006-08-31 08:53:58 -07:00
|
|
|
{
|
|
|
|
|
switch (target->expected_type) {
|
|
|
|
|
case CAIRO_SURFACE_TYPE_IMAGE:
|
2006-08-31 11:53:16 -07:00
|
|
|
if (strcmp (target->name, "pdf") == 0 ||
|
|
|
|
|
strcmp (target->name, "ps") == 0)
|
2006-08-31 08:53:58 -07:00
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
case CAIRO_SURFACE_TYPE_XLIB:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_XCB:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_GLITZ:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_QUARTZ:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_WIN32:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_BEOS:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_DIRECTFB:
|
|
|
|
|
return TRUE;
|
|
|
|
|
case CAIRO_SURFACE_TYPE_PDF:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_PS:
|
|
|
|
|
case CAIRO_SURFACE_TYPE_SVG:
|
|
|
|
|
default:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-31 12:34:21 -07:00
|
|
|
static const char *
|
|
|
|
|
_content_to_string (cairo_content_t content)
|
|
|
|
|
{
|
|
|
|
|
switch (content) {
|
|
|
|
|
case CAIRO_CONTENT_COLOR:
|
|
|
|
|
return "rgb";
|
|
|
|
|
case CAIRO_CONTENT_ALPHA:
|
|
|
|
|
return "a";
|
|
|
|
|
case CAIRO_CONTENT_COLOR_ALPHA:
|
|
|
|
|
return "rgba";
|
|
|
|
|
default:
|
|
|
|
|
return "<unknown_content>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-31 13:22:17 -07:00
|
|
|
typedef struct _stats
|
|
|
|
|
{
|
|
|
|
|
double mean;
|
|
|
|
|
double std_dev;
|
|
|
|
|
} stats_t;
|
|
|
|
|
|
2006-08-31 17:43:40 -07:00
|
|
|
static int
|
2006-09-06 00:15:49 -07:00
|
|
|
compare_cairo_perf_ticks (const void *_a, const void *_b)
|
2006-08-31 17:43:40 -07:00
|
|
|
{
|
2006-09-06 00:15:49 -07:00
|
|
|
const cairo_perf_ticks_t *a = _a;
|
|
|
|
|
const cairo_perf_ticks_t *b = _b;
|
2006-08-31 17:43:40 -07:00
|
|
|
|
2006-09-05 22:36:56 -07:00
|
|
|
if (*a > *b)
|
|
|
|
|
return 1;
|
|
|
|
|
if (*a < *b)
|
|
|
|
|
return -1;
|
|
|
|
|
return 0;
|
2006-08-31 17:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
2006-08-31 13:22:17 -07:00
|
|
|
static void
|
2006-09-06 00:15:49 -07:00
|
|
|
_compute_stats (cairo_perf_ticks_t *values, int num_values, stats_t *stats)
|
2006-08-31 13:22:17 -07:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
double sum, delta;
|
|
|
|
|
|
|
|
|
|
sum = 0.0;
|
2006-09-06 00:52:06 -07:00
|
|
|
for (i = 0; i < num_values; i++)
|
2006-08-31 13:22:17 -07:00
|
|
|
sum += values[i];
|
|
|
|
|
|
|
|
|
|
stats->mean = sum / num_values;
|
|
|
|
|
|
|
|
|
|
sum = 0.0;
|
2006-09-06 00:52:06 -07:00
|
|
|
for (i = 0; i < num_values; i++) {
|
2006-08-31 13:22:17 -07:00
|
|
|
delta = values[i] - stats->mean;
|
|
|
|
|
sum += delta * delta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Let's use a std. deviation normalized to the mean for easier
|
|
|
|
|
* comparison. */
|
|
|
|
|
stats->std_dev = sqrt(sum / num_values) / stats->mean;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-31 07:19:05 -07:00
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
2006-08-31 13:22:17 -07:00
|
|
|
int i, j, k;
|
2006-09-09 14:55:57 -07:00
|
|
|
cairo_boilerplate_target_t *target;
|
2006-08-31 07:19:05 -07:00
|
|
|
cairo_perf_t *perf;
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
unsigned int size;
|
2006-09-06 00:15:49 -07:00
|
|
|
cairo_perf_ticks_t *times;
|
2006-08-31 13:22:17 -07:00
|
|
|
stats_t stats;
|
2006-09-06 05:09:19 -07:00
|
|
|
const char *cairo_test_target = getenv ("CAIRO_TEST_TARGET");
|
2006-09-14 12:59:31 -07:00
|
|
|
double ms;
|
|
|
|
|
int test_number;
|
2006-08-31 07:19:05 -07:00
|
|
|
|
2006-08-31 13:22:17 -07:00
|
|
|
if (getenv("CAIRO_PERF_ITERATIONS"))
|
|
|
|
|
cairo_perf_iterations = strtol(getenv("CAIRO_PERF_ITERATIONS"), NULL, 0);
|
|
|
|
|
|
2006-09-06 00:15:49 -07:00
|
|
|
times = xmalloc (cairo_perf_iterations * sizeof (cairo_perf_ticks_t));
|
2006-08-31 13:22:17 -07:00
|
|
|
|
2006-08-31 07:19:05 -07:00
|
|
|
for (i = 0; targets[i].name; i++) {
|
|
|
|
|
target = &targets[i];
|
2006-08-31 08:53:58 -07:00
|
|
|
if (! target_is_measurable (target))
|
|
|
|
|
continue;
|
2006-09-06 05:09:19 -07:00
|
|
|
if (cairo_test_target && ! strstr (cairo_test_target, target->name))
|
|
|
|
|
continue;
|
2006-09-14 12:59:31 -07:00
|
|
|
|
|
|
|
|
test_number = 0;
|
|
|
|
|
|
2006-08-31 07:19:05 -07:00
|
|
|
for (j = 0; perfs[j].name; j++) {
|
|
|
|
|
perf = &perfs[j];
|
|
|
|
|
for (size = perf->min_size; size <= perf->max_size; size *= 2) {
|
2006-09-09 14:55:57 -07:00
|
|
|
surface = (target->create_surface) (perf->name,
|
|
|
|
|
target->content,
|
|
|
|
|
size, size,
|
2006-09-09 16:40:58 -07:00
|
|
|
CAIRO_BOILERPLATE_MODE_PERF,
|
2006-09-09 14:55:57 -07:00
|
|
|
&target->closure);
|
2006-09-09 20:17:08 -07:00
|
|
|
cairo_perf_timer_set_finalize (target->wait_for_rendering, target->closure);
|
2006-08-31 07:19:05 -07:00
|
|
|
cr = cairo_create (surface);
|
2006-09-05 22:36:56 -07:00
|
|
|
for (k =0; k < cairo_perf_iterations; k++) {
|
2006-09-05 22:58:33 -07:00
|
|
|
cairo_perf_yield ();
|
2006-09-06 00:15:49 -07:00
|
|
|
times[k] = perf->run (cr, size, size);
|
2006-09-05 22:36:56 -07:00
|
|
|
}
|
2006-09-06 00:52:06 -07:00
|
|
|
|
|
|
|
|
qsort (times, cairo_perf_iterations,
|
|
|
|
|
sizeof (cairo_perf_ticks_t), compare_cairo_perf_ticks);
|
|
|
|
|
|
|
|
|
|
/* Assume the slowest 15% are outliers, and ignore */
|
|
|
|
|
_compute_stats (times, .85 * cairo_perf_iterations, &stats);
|
|
|
|
|
|
2006-08-31 13:22:17 -07:00
|
|
|
if (i==0 && j==0 && size == perf->min_size)
|
2006-09-14 12:59:31 -07:00
|
|
|
printf ("[ # ] %8s-%-4s %27s %9s %5s %s\n",
|
|
|
|
|
"backend", "content", "test-size", "mean ms",
|
|
|
|
|
"std dev.", "iterations");
|
|
|
|
|
|
|
|
|
|
printf ("[%3d] %8s-%-4s %25s-%-3d ",
|
|
|
|
|
test_number, target->name, _content_to_string (target->content),
|
|
|
|
|
perf->name, size);
|
|
|
|
|
|
|
|
|
|
printf ("%#9.3f %#5.2f%% % 5d\n",
|
|
|
|
|
(stats.mean * 1000.0) / cairo_perf_ticks_per_second (),
|
2006-09-06 00:15:49 -07:00
|
|
|
stats.std_dev * 100.0, cairo_perf_iterations);
|
2006-09-14 12:59:31 -07:00
|
|
|
|
|
|
|
|
test_number++;
|
2006-08-31 07:19:05 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-31 11:51:28 -07:00
|
|
|
cairo_perf_t perfs[] = {
|
2006-09-14 12:59:31 -07:00
|
|
|
{ "paint_over_solid", paint_over_solid, 64, 512 },
|
|
|
|
|
{ "paint_over_solid_alpha", paint_over_solid_alpha, 64, 512 },
|
|
|
|
|
{ "paint_source_solid", paint_over_solid, 64, 512 },
|
|
|
|
|
{ "paint_source_solid_alpha", paint_over_solid_alpha, 64, 512 },
|
|
|
|
|
|
|
|
|
|
{ "paint_over_surf_rgb24", paint_over_solid, 64, 512 },
|
|
|
|
|
{ "paint_over_surf_argb32", paint_over_solid_alpha, 64, 512 },
|
|
|
|
|
{ "paint_source_surf_rgb24", paint_over_solid, 64, 512 },
|
|
|
|
|
{ "paint_source_surf_argb32", paint_over_solid_alpha, 64, 512 },
|
|
|
|
|
|
|
|
|
|
{ "tessellate-16", tessellate_16, 100, 100},
|
|
|
|
|
{ "tessellate-64", tessellate_64, 100, 100},
|
2006-09-06 05:17:01 -07:00
|
|
|
{ "tessellate-256", tessellate_256, 100, 100},
|
2006-08-31 11:51:28 -07:00
|
|
|
{ NULL }
|
|
|
|
|
};
|