[cairo-commit] 10 commits - boilerplate/cairo-boilerplate.h
perf/cairo-perf.c perf/cairo-perf.h perf/cairo-perf-posix.c
perf/cairo-perf-timer.h perf/cairo-perf-timer-posix.c
perf/cairo-perf-timer-win32.c perf/cairo-perf-win32.c
perf/Makefile.am perf/paint.c perf/README
Carl Worth
cworth at kemper.freedesktop.org
Wed Sep 6 01:38:17 PDT 2006
boilerplate/cairo-boilerplate.h | 31 ++++++
perf/Makefile.am | 4
perf/README | 18 +--
perf/cairo-perf-posix.c | 187 ++++++++++++++++++++++++++++++++++++++++
perf/cairo-perf-timer-posix.c | 83 -----------------
perf/cairo-perf-timer-win32.c | 76 ----------------
perf/cairo-perf-win32.c | 54 ++++++-----
perf/cairo-perf.c | 48 +++++-----
perf/cairo-perf.h | 26 ++++-
perf/paint.c | 35 +++++--
10 files changed, 331 insertions(+), 231 deletions(-)
New commits:
diff-tree d9082d59db90a4373ec52d932b87234e3c39b21b (from 1085d99bc3c2f12ae37be0489deedac2475ab376)
Author: Carl Worth <cworth at cworth.org>
Date: Wed Sep 6 01:37:13 2006 -0700
Prefer CPU performance counters (if available) over gettimeofday.
I've seen this improve the std. deviation often by a factor of 2
and occasionally up to a factor of 10. It is sometimes not much
better, but never seems to be appreciably worse compared to using
gettimeofday.
Thanks to David A. Schleef <ds at schleef.org> and his liboil for
the implementation.
diff --git a/perf/cairo-perf-posix.c b/perf/cairo-perf-posix.c
index 452f058..2105f9c 100644
--- a/perf/cairo-perf-posix.c
+++ b/perf/cairo-perf-posix.c
@@ -25,6 +25,34 @@
* Carl Worth <cworth at cworth.org>
*/
+/* Portions of this file come from liboil:
+ *
+ * LIBOIL - Library of Optimized Inner Loops
+ * Copyright (c) 2003,2004 David A. Schleef <ds at schleef.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include <signal.h>
#include <sys/time.h>
#include <unistd.h>
@@ -36,37 +64,117 @@
/* timers */
+#if defined(__i386__) || defined(__amd64__)
+static inline unsigned long
+oil_profile_stamp_rdtsc (void)
+{
+ unsigned long ts;
+ __asm__ __volatile__("rdtsc\n" : "=a" (ts) : : "edx");
+ return ts;
+}
+#define OIL_STAMP oil_profile_stamp_rdtsc
+#endif
+
+#if defined(__powerpc__) || defined(__PPC__) || defined(__ppc__)
+static inline cairo_perf_ticks_t
+oil_profile_stamp_tb(void)
+{
+ unsigned long ts;
+ __asm__ __volatile__("mftb %0\n" : "=r" (ts));
+ return ts;
+}
+#define OIL_STAMP oil_profile_stamp_tb
+#endif
+
+#if defined(__alpha__)
+static inline cairo_perf_ticks_t
+oil_profile_stamp_alpha(void)
+{
+ unsigned int ts;
+ __asm__ __volatile__ ("rpcc %0\n" : "=r"(ts));
+ return ts;
+}
+#define OIL_STAMP oil_profile_stamp_alpha
+#endif
+
+#if defined(__s390__)
+static cairo_perf_ticks_t
+oil_profile_stamp_s390(void)
+{
+ uint64_t ts;
+ __asm__ __volatile__ ("STCK %0\n" : : "m" (ts));
+ return ts;
+}
+#define OIL_STAMP oil_profile_stamp_s390
+#endif
+
typedef struct _cairo_perf_timer
{
- struct timeval start;
- struct timeval stop;
+#ifdef OIL_STAMP
+ cairo_perf_ticks_t start;
+ cairo_perf_ticks_t stop;
+#else
+ struct timeval tv_start;
+ struct timeval tv_stop;
+#endif
} cairo_perf_timer_t;
static cairo_perf_timer_t timer;
void
cairo_perf_timer_start (void) {
- gettimeofday (&timer.start, NULL);
+#ifdef OIL_STAMP
+ timer.start = OIL_STAMP ();
+#else
+ gettimeofday (&timer.tv_start, NULL);
+#endif
}
void
cairo_perf_timer_stop (void) {
- gettimeofday (&timer.stop, NULL);
+#ifdef OIL_STAMP
+ timer.stop = OIL_STAMP ();
+#else
+ gettimeofday (&timer.tv_stop, NULL);
+#endif
}
cairo_perf_ticks_t
cairo_perf_timer_elapsed (void) {
- cairo_perf_ticks_t usec;
+ cairo_perf_ticks_t ticks;
- usec = (timer.stop.tv_sec - timer.start.tv_sec) * 1000000;
- usec += (timer.stop.tv_usec - timer.start.tv_usec);
+#ifdef OIL_STAMP
+ ticks = (timer.stop - timer.start);
+#else
+ ticks = (timer.tv_stop.tv_sec - timer.tv_start.tv_sec) * 1000000;
+ ticks += (timer.tv_stop.tv_usec - timer.tv_start.tv_usec);
+#endif
- return usec;
+ return ticks;
}
cairo_perf_ticks_t
cairo_perf_ticks_per_second (void) {
+#ifdef OIL_STAMP
+ static cairo_perf_ticks_t tps = 0;
+ /* XXX: This is obviously not stable in light of changing CPU speed. */
+ if (tps == 0) {
+ struct timeval tv_start, tv_stop;
+ double tv_elapsed;
+ cairo_perf_timer_start ();
+ gettimeofday (&tv_start, NULL);
+ sleep (1);
+ cairo_perf_timer_stop ();
+ gettimeofday (&tv_stop, NULL);
+ tv_elapsed = ((tv_stop.tv_sec - tv_start.tv_sec) +
+ + (tv_stop.tv_usec - tv_start.tv_usec) / 1000000.0);
+ tps = round (cairo_perf_timer_elapsed () / tv_elapsed);
+ }
+ return tps;
+#else
+ /* For gettimeofday the units are micro-seconds */
return 1000000;
+#endif
}
/* yield */
diff-tree 1085d99bc3c2f12ae37be0489deedac2475ab376 (from 3c407aa80a43e1724e732482ada5ad6718fe33ae)
Author: Carl Worth <cworth at cworth.org>
Date: Wed Sep 6 00:56:56 2006 -0700
perf/README: Update due to cairo_perf_timer API changes
diff --git a/perf/README b/perf/README
index 9db6ab4..d577cd7 100644
--- a/perf/README
+++ b/perf/README
@@ -36,32 +36,26 @@ Here is the basic structure of a perform
* Please copy the MIT blurb as in other tests
*/
- #include "cairo-perf"
+ #include "cairo-perf.h"
- double
+ cairo_perf_ticks_t
my_new_test (cairo_t *cr, int width, int height)
{
- cairo_perf_timer_t timer;
-
/* First do any setup for which the execution time should not
* be measured. For example, this might include loading
* images from disk, creating patterns, etc. */
- timer_start (&timer);
+ cairo_perf_timer_start ();
/* Now make the real cairo calls to be measured */
- timer_stop (&timer);
+ cairo_perf_timer_stop ();
/* Finally, any cleanup */
- /* Then return the inverse of the time that elapsed so that
- * the return value measures a rate, (how many times per
- * second your code can be executed). We use rates rather
- * than times for a "bigger is better" effect in the
- * results. */
+ /* Then return the time that elapsed. */
- return 1.0 / timer_elapsed (&timer);
+ return cairo_perf_timer_elapsed ();
}
That's really all there is to writing a new test. Then, to fully
diff-tree 3c407aa80a43e1724e732482ada5ad6718fe33ae (from 3519887f1838a8ea67784eecec31feb9a37b4828)
Author: Carl Worth <cworth at cworth.org>
Date: Wed Sep 6 00:53:52 2006 -0700
perf-paint: Spend more iterations on smaller sizes to balance testing.
The values here are chosen to try to equalize the standard deviation
of the various tests.
diff --git a/perf/paint.c b/perf/paint.c
index 22c5188..2501a33 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -25,14 +25,28 @@
#include "cairo-perf.h"
+static int
+iters_for_size (int size)
+{
+ if (size <= 64)
+ return 8;
+ else if (size <= 128)
+ return 4;
+ else if (size <= 256)
+ return 2;
+ else
+ return 1;
+}
+
static cairo_perf_ticks_t
-do_paint (cairo_t *cr)
+do_paint (cairo_t *cr, int size)
{
int i;
+ int iters = iters_for_size (size);
cairo_perf_timer_start ();
- for (i=0; i < 3; i++)
+ for (i=0; i < iters; i++)
cairo_paint (cr);
cairo_perf_timer_stop ();
@@ -45,7 +59,7 @@ paint (cairo_t *cr, int width, int heigh
{
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
- return do_paint (cr);
+ return do_paint (cr, width);
}
cairo_perf_ticks_t
@@ -53,6 +67,6 @@ paint_alpha (cairo_t *cr, int width, int
{
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
- return do_paint (cr);
+ return do_paint (cr, width);
}
diff-tree 3519887f1838a8ea67784eecec31feb9a37b4828 (from d31037e421e275cd1d6d1440d6b5bdb817f992bc)
Author: Carl Worth <cworth at cworth.org>
Date: Wed Sep 6 00:52:06 2006 -0700
perf: Move sorting and discarding outside of compute_stats. Adjust discard to slowest 15% only.
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 4d98d32..2390983 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -112,20 +112,15 @@ _compute_stats (cairo_perf_ticks_t *valu
{
int i;
double sum, delta;
- int chop = num_values / 5;
-
- qsort (values, num_values, sizeof (double), compare_cairo_perf_ticks);
-
- num_values -= 2 * chop;
sum = 0.0;
- for (i = chop; i < chop + num_values; i++)
+ for (i = 0; i < num_values; i++)
sum += values[i];
stats->mean = sum / num_values;
sum = 0.0;
- for (i = chop; i < chop + num_values; i++) {
+ for (i = 0; i < num_values; i++) {
delta = values[i] - stats->mean;
sum += delta * delta;
}
@@ -168,7 +163,13 @@ main (int argc, char *argv[])
cairo_perf_yield ();
times[k] = perf->run (cr, size, size);
}
- _compute_stats (times, cairo_perf_iterations, &stats);
+
+ 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);
+
if (i==0 && j==0 && size == perf->min_size)
printf ("backend-content\ttest-size\tmean time\tstd dev.\titerations\n");
printf ("%s-%s\t%s-%d\t%g\t%g%%\t%d\n",
diff-tree d31037e421e275cd1d6d1440d6b5bdb817f992bc (from 9d0d38e0a0307580ba69a96e239507cc9559cd99)
Author: Carl Worth <cworth at cworth.org>
Date: Wed Sep 6 00:15:49 2006 -0700
perf: Report times not rates. Interface in integers not doubles.
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index ea9ccf3..f774909 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -36,6 +36,37 @@
#include <cairo.h>
#include <string.h>
+#if HAVE_STDINT_H
+# include <stdint.h>
+#elif HAVE_INTTYPES_H
+# include <inttypes.h>
+#elif HAVE_SYS_INT_TYPES_H
+# include <sys/int_types.h>
+#elif defined(_MSC_VER)
+ typedef __int8 int8_t;
+ typedef unsigned __int8 uint8_t;
+ typedef __int16 int16_t;
+ typedef unsigned __int16 uint16_t;
+ typedef __int32 int32_t;
+ typedef unsigned __int32 uint32_t;
+ typedef __int64 int64_t;
+ typedef unsigned __int64 uint64_t;
+# ifndef HAVE_UINT64_T
+# define HAVE_UINT64_T 1
+# endif
+# ifndef INT16_MIN
+# define INT16_MIN (-32767-1)
+# endif
+# ifndef INT16_MAX
+# define INT16_MAX (32767)
+# endif
+# ifndef UINT16_MAX
+# define UINT16_MAX (65535)
+# endif
+#else
+#error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
+#endif
+
#include "xmalloc.h"
#ifndef CAIRO_BOILERPLATE_LOG
diff --git a/perf/cairo-perf-posix.c b/perf/cairo-perf-posix.c
index e710d52..452f058 100644
--- a/perf/cairo-perf-posix.c
+++ b/perf/cairo-perf-posix.c
@@ -54,14 +54,19 @@ cairo_perf_timer_stop (void) {
gettimeofday (&timer.stop, NULL);
}
-double
+cairo_perf_ticks_t
cairo_perf_timer_elapsed (void) {
- double d;
+ cairo_perf_ticks_t usec;
- d = timer.stop.tv_sec - timer.start.tv_sec;
- d += (timer.stop.tv_usec - timer.start.tv_usec) / 1000000.0;
+ usec = (timer.stop.tv_sec - timer.start.tv_sec) * 1000000;
+ usec += (timer.stop.tv_usec - timer.start.tv_usec);
- return d;
+ return usec;
+}
+
+cairo_perf_ticks_t
+cairo_perf_ticks_per_second (void) {
+ return 1000000;
}
/* yield */
diff --git a/perf/cairo-perf-win32.c b/perf/cairo-perf-win32.c
index 22cea62..dd82267 100644
--- a/perf/cairo-perf-win32.c
+++ b/perf/cairo-perf-win32.c
@@ -52,17 +52,21 @@ cairo_perf_timer_stop (void) {
QueryPerformanceCounter(&timer.stop);
}
-double
+cairo_perf_ticks_t
cairo_perf_timer_elapsed (void) {
- double d;
+ return (timer.stop.QuadPart - timer.start.QuadPart);
+}
+
+cairo_perf_ticks_t
+cairo_perf_ticks_per_second (void) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
- d = (timer.stop.QuadPart - timer.start.QuadPart) / (double) freq.QuadPart;
- return d;
+ return freq;
}
+
/* yield */
void
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index c146d70..4d98d32 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -95,10 +95,10 @@ typedef struct _stats
} stats_t;
static int
-compare_doubles (const void *_a, const void *_b)
+compare_cairo_perf_ticks (const void *_a, const void *_b)
{
- const double *a = _a;
- const double *b = _b;
+ const cairo_perf_ticks_t *a = _a;
+ const cairo_perf_ticks_t *b = _b;
if (*a > *b)
return 1;
@@ -108,13 +108,13 @@ compare_doubles (const void *_a, const v
}
static void
-_compute_stats (double *values, int num_values, stats_t *stats)
+_compute_stats (cairo_perf_ticks_t *values, int num_values, stats_t *stats)
{
int i;
double sum, delta;
int chop = num_values / 5;
- qsort (values, num_values, sizeof (double), compare_doubles);
+ qsort (values, num_values, sizeof (double), compare_cairo_perf_ticks);
num_values -= 2 * chop;
@@ -144,13 +144,13 @@ main (int argc, char *argv[])
cairo_surface_t *surface;
cairo_t *cr;
unsigned int size;
- double *rates;
+ cairo_perf_ticks_t *times;
stats_t stats;
if (getenv("CAIRO_PERF_ITERATIONS"))
cairo_perf_iterations = strtol(getenv("CAIRO_PERF_ITERATIONS"), NULL, 0);
- rates = xmalloc (cairo_perf_iterations * sizeof (double));
+ times = xmalloc (cairo_perf_iterations * sizeof (cairo_perf_ticks_t));
for (i = 0; targets[i].name; i++) {
target = &targets[i];
@@ -166,15 +166,16 @@ main (int argc, char *argv[])
cr = cairo_create (surface);
for (k =0; k < cairo_perf_iterations; k++) {
cairo_perf_yield ();
- rates[k] = perf->run (cr, size, size);
+ times[k] = perf->run (cr, size, size);
}
- _compute_stats (rates, cairo_perf_iterations, &stats);
+ _compute_stats (times, cairo_perf_iterations, &stats);
if (i==0 && j==0 && size == perf->min_size)
- printf ("backend-content\ttest-size\trate\tstd dev.\titerations\n");
+ printf ("backend-content\ttest-size\tmean time\tstd dev.\titerations\n");
printf ("%s-%s\t%s-%d\t%g\t%g%%\t%d\n",
target->name, _content_to_string (target->content),
perf->name, size,
- stats.mean, stats.std_dev * 100.0, cairo_perf_iterations);
+ stats.mean / cairo_perf_ticks_per_second (),
+ stats.std_dev * 100.0, cairo_perf_iterations);
}
}
}
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index d4f049e..a564418 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -38,17 +38,23 @@ cairo_perf_timer_start (void);
void
cairo_perf_timer_stop (void);
-double
+typedef uint64_t cairo_perf_ticks_t;
+
+cairo_perf_ticks_t
cairo_perf_timer_elapsed (void);
+cairo_perf_ticks_t
+cairo_perf_ticks_per_second (void);
+
/* yield */
void
cairo_perf_yield (void);
-typedef double (*cairo_perf_func_t) (cairo_t *cr, int width, int height);
+typedef cairo_perf_ticks_t
+(*cairo_perf_func_t) (cairo_t *cr, int width, int height);
-#define CAIRO_PERF_DECL(func) double func (cairo_t *cr, int width, int height)
+#define CAIRO_PERF_DECL(func) cairo_perf_ticks_t func (cairo_t *cr, int width, int height)
CAIRO_PERF_DECL (paint);
CAIRO_PERF_DECL (paint_alpha);
diff --git a/perf/paint.c b/perf/paint.c
index b2f36b4..22c5188 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -25,7 +25,7 @@
#include "cairo-perf.h"
-static double
+static cairo_perf_ticks_t
do_paint (cairo_t *cr)
{
int i;
@@ -37,10 +37,10 @@ do_paint (cairo_t *cr)
cairo_perf_timer_stop ();
- return 1.0 / cairo_perf_timer_elapsed ();
+ return cairo_perf_timer_elapsed ();
}
-double
+cairo_perf_ticks_t
paint (cairo_t *cr, int width, int height)
{
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
@@ -48,7 +48,7 @@ paint (cairo_t *cr, int width, int heigh
return do_paint (cr);
}
-double
+cairo_perf_ticks_t
paint_alpha (cairo_t *cr, int width, int height)
{
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
diff-tree 9d0d38e0a0307580ba69a96e239507cc9559cd99 (from 9f51fcc888c4b036c535a6a4042ae8c6859f3261)
Author: Carl Worth <cworth at cworth.org>
Date: Tue Sep 5 22:58:33 2006 -0700
perf: Rename functions in line with cairo's naming guidelines
diff --git a/perf/cairo-perf-posix.c b/perf/cairo-perf-posix.c
index 685d7e5..e710d52 100644
--- a/perf/cairo-perf-posix.c
+++ b/perf/cairo-perf-posix.c
@@ -36,30 +36,30 @@
/* timers */
-static cairo_perf_timer_t tr;
-
-struct _cairo_perf_timer_t
+typedef struct _cairo_perf_timer
{
struct timeval start;
struct timeval stop;
-};
+} cairo_perf_timer_t;
+
+static cairo_perf_timer_t timer;
void
-timer_start (void) {
- gettimeofday (&tr.start, NULL);
+cairo_perf_timer_start (void) {
+ gettimeofday (&timer.start, NULL);
}
void
-timer_stop (void) {
- gettimeofday (&tr.stop, NULL);
+cairo_perf_timer_stop (void) {
+ gettimeofday (&timer.stop, NULL);
}
double
-timer_elapsed (void) {
+cairo_perf_timer_elapsed (void) {
double d;
- d = tr.stop.tv_sec - tr.start.tv_sec;
- d += (tr.stop.tv_usec - tr.start.tv_usec) / 1000000.0;
+ d = timer.stop.tv_sec - timer.start.tv_sec;
+ d += (timer.stop.tv_usec - timer.start.tv_usec) / 1000000.0;
return d;
}
@@ -67,7 +67,7 @@ timer_elapsed (void) {
/* yield */
void
-yield (void) {
+cairo_perf_yield (void) {
#ifdef _POSIX_PRIORITY_SCHEDULING
sched_yield ();
#endif
diff --git a/perf/cairo-perf-win32.c b/perf/cairo-perf-win32.c
index f0caa73..22cea62 100644
--- a/perf/cairo-perf-win32.c
+++ b/perf/cairo-perf-win32.c
@@ -34,38 +34,38 @@
/* timers */
-struct _cairo_perf_timer_t
+typedef struct _cairo_perf_timer
{
LARGE_INTEGER start;
LARGE_INTEGER stop;
-};
+} cairo_perf_timer_t;
-static cairo_perf_timer_t tr;
+static cairo_perf_timer_t timer;
void
-timer_start (void) {
- QueryPerformanceCounter(&tr.start);
+cairo_perf_timer_start (void) {
+ QueryPerformanceCounter(&timer.start);
}
void
-timer_stop (void) {
- QueryPerformanceCounter(&tr.stop);
+cairo_perf_timer_stop (void) {
+ QueryPerformanceCounter(&timer.stop);
}
double
-timer_elapsed (void) {
+cairo_perf_timer_elapsed (void) {
double d;
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
- d = (tr.stop.QuadPart - tr.start.QuadPart) / (double) freq.QuadPart;
+ d = (timer.stop.QuadPart - timer.start.QuadPart) / (double) freq.QuadPart;
return d;
}
/* yield */
void
-yield (void) {
+cairo_perf_yield (void) {
SleepEx(0, TRUE);
}
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 9e51791..c146d70 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -165,7 +165,7 @@ main (int argc, char *argv[])
&target->closure);
cr = cairo_create (surface);
for (k =0; k < cairo_perf_iterations; k++) {
- yield ();
+ cairo_perf_yield ();
rates[k] = perf->run (cr, size, size);
}
_compute_stats (rates, cairo_perf_iterations, &stats);
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 34d2bbd..d4f049e 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -30,23 +30,21 @@
#include "cairo-boilerplate.h"
-typedef struct _cairo_perf_timer_t cairo_perf_timer_t;
-
/* timers */
void
-timer_start (void);
+cairo_perf_timer_start (void);
void
-timer_stop (void);
+cairo_perf_timer_stop (void);
double
-timer_elapsed (void);
+cairo_perf_timer_elapsed (void);
/* yield */
void
-yield (void);
+cairo_perf_yield (void);
typedef double (*cairo_perf_func_t) (cairo_t *cr, int width, int height);
diff --git a/perf/paint.c b/perf/paint.c
index 858f15d..b2f36b4 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -30,14 +30,14 @@ do_paint (cairo_t *cr)
{
int i;
- timer_start ();
+ cairo_perf_timer_start ();
for (i=0; i < 3; i++)
cairo_paint (cr);
- timer_stop ();
+ cairo_perf_timer_stop ();
- return 1.0 / timer_elapsed ();
+ return 1.0 / cairo_perf_timer_elapsed ();
}
double
diff-tree 9f51fcc888c4b036c535a6a4042ae8c6859f3261 (from 499a3a7c4772bb0f446f89a9c6e9430bd31c1218)
Author: Carl Worth <cworth at cworth.org>
Date: Tue Sep 5 22:53:12 2006 -0700
perf: Fold cairo-perf-timer.h into cairo-perf.h
diff --git a/perf/Makefile.am b/perf/Makefile.am
index 35f56f8..f4ce905 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -20,9 +20,9 @@ cairo_perf_SOURCES = \
paint.c
if CAIRO_HAS_WIN32_SURFACE
-cairo_perf_SOURCES += cairo-perf-timer-win32.c
+cairo_perf_SOURCES += cairo-perf-win32.c
else
-cairo_perf_SOURCES += cairo-perf-timer-posix.c
+cairo_perf_SOURCES += cairo-perf-posix.c
endif
LDADD = $(top_builddir)/boilerplate/libcairoboilerplate.la \
diff --git a/perf/cairo-perf-posix.c b/perf/cairo-perf-posix.c
new file mode 100644
index 0000000..685d7e5
--- /dev/null
+++ b/perf/cairo-perf-posix.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2006 Mozilla Corporation
+ * 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
+ * the authors not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. The authors make no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
+ * 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.
+ *
+ * Authors: Vladimir Vukicevic <vladimir at pobox.com>
+ * Carl Worth <cworth at cworth.org>
+ */
+
+#include <signal.h>
+#include <sys/time.h>
+#include <unistd.h>
+#ifdef _POSIX_PRIORITY_SCHEDULING
+#include <sched.h>
+#endif
+
+#include "cairo-perf.h"
+
+/* timers */
+
+static cairo_perf_timer_t tr;
+
+struct _cairo_perf_timer_t
+{
+ struct timeval start;
+ struct timeval stop;
+};
+
+void
+timer_start (void) {
+ gettimeofday (&tr.start, NULL);
+}
+
+void
+timer_stop (void) {
+ gettimeofday (&tr.stop, NULL);
+}
+
+double
+timer_elapsed (void) {
+ double d;
+
+ d = tr.stop.tv_sec - tr.start.tv_sec;
+ d += (tr.stop.tv_usec - tr.start.tv_usec) / 1000000.0;
+
+ return d;
+}
+
+/* yield */
+
+void
+yield (void) {
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ sched_yield ();
+#endif
+}
diff --git a/perf/cairo-perf-timer-posix.c b/perf/cairo-perf-timer-posix.c
deleted file mode 100644
index 685d7e5..0000000
--- a/perf/cairo-perf-timer-posix.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright © 2006 Mozilla Corporation
- * 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
- * the authors not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. The authors make no representations about the
- * suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
- * 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.
- *
- * Authors: Vladimir Vukicevic <vladimir at pobox.com>
- * Carl Worth <cworth at cworth.org>
- */
-
-#include <signal.h>
-#include <sys/time.h>
-#include <unistd.h>
-#ifdef _POSIX_PRIORITY_SCHEDULING
-#include <sched.h>
-#endif
-
-#include "cairo-perf.h"
-
-/* timers */
-
-static cairo_perf_timer_t tr;
-
-struct _cairo_perf_timer_t
-{
- struct timeval start;
- struct timeval stop;
-};
-
-void
-timer_start (void) {
- gettimeofday (&tr.start, NULL);
-}
-
-void
-timer_stop (void) {
- gettimeofday (&tr.stop, NULL);
-}
-
-double
-timer_elapsed (void) {
- double d;
-
- d = tr.stop.tv_sec - tr.start.tv_sec;
- d += (tr.stop.tv_usec - tr.start.tv_usec) / 1000000.0;
-
- return d;
-}
-
-/* yield */
-
-void
-yield (void) {
-#ifdef _POSIX_PRIORITY_SCHEDULING
- sched_yield ();
-#endif
-}
diff --git a/perf/cairo-perf-timer-win32.c b/perf/cairo-perf-timer-win32.c
deleted file mode 100644
index f0caa73..0000000
--- a/perf/cairo-perf-timer-win32.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright © 2006 Mozilla Corporation
- * 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
- * the authors not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. The authors make no representations about the
- * suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
- * 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.
- *
- * Authors: Vladimir Vukicevic <vladimir at pobox.com>
- * Carl Worth <cworth at cworth.org>
- */
-
-#define USE_WINAPI
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-#include "cairo-perf.h"
-
-/* timers */
-
-struct _cairo_perf_timer_t
-{
- LARGE_INTEGER start;
- LARGE_INTEGER stop;
-};
-
-static cairo_perf_timer_t tr;
-
-void
-timer_start (void) {
- QueryPerformanceCounter(&tr.start);
-}
-
-void
-timer_stop (void) {
- QueryPerformanceCounter(&tr.stop);
-}
-
-double
-timer_elapsed (void) {
- double d;
- LARGE_INTEGER freq;
-
- QueryPerformanceFrequency(&freq);
-
- d = (tr.stop.QuadPart - tr.start.QuadPart) / (double) freq.QuadPart;
- return d;
-}
-
-/* yield */
-
-void
-yield (void) {
- SleepEx(0, TRUE);
-}
diff --git a/perf/cairo-perf-timer.h b/perf/cairo-perf-timer.h
deleted file mode 100644
index fbe67a3..0000000
--- a/perf/cairo-perf-timer.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright © 2006 Mozilla Corporation
- * 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
- * the authors not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. The authors make no representations about the
- * suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
- * 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.
- *
- * Authors: Vladimir Vukicevic <vladimir at pobox.com>
- * Carl Worth <cworth at cworth.org>
- */
-
-#ifndef _TIMER_ALARM_H_
-#define _TIMER_ALARM_H_
-
-#include "cairo-perf.h"
-
-typedef struct _cairo_perf_timer_t cairo_perf_timer_t;
-
-/* timers */
-
-void
-timer_start (void);
-
-void
-timer_stop (void);
-
-double
-timer_elapsed (void);
-
-/* yield */
-
-void
-yield (void);
-
-#endif
diff --git a/perf/cairo-perf-win32.c b/perf/cairo-perf-win32.c
new file mode 100644
index 0000000..f0caa73
--- /dev/null
+++ b/perf/cairo-perf-win32.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2006 Mozilla Corporation
+ * 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
+ * the authors not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. The authors make no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
+ * 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.
+ *
+ * Authors: Vladimir Vukicevic <vladimir at pobox.com>
+ * Carl Worth <cworth at cworth.org>
+ */
+
+#define USE_WINAPI
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "cairo-perf.h"
+
+/* timers */
+
+struct _cairo_perf_timer_t
+{
+ LARGE_INTEGER start;
+ LARGE_INTEGER stop;
+};
+
+static cairo_perf_timer_t tr;
+
+void
+timer_start (void) {
+ QueryPerformanceCounter(&tr.start);
+}
+
+void
+timer_stop (void) {
+ QueryPerformanceCounter(&tr.stop);
+}
+
+double
+timer_elapsed (void) {
+ double d;
+ LARGE_INTEGER freq;
+
+ QueryPerformanceFrequency(&freq);
+
+ d = (tr.stop.QuadPart - tr.start.QuadPart) / (double) freq.QuadPart;
+ return d;
+}
+
+/* yield */
+
+void
+yield (void) {
+ SleepEx(0, TRUE);
+}
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index d9e5ad8..34d2bbd 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -30,7 +30,23 @@
#include "cairo-boilerplate.h"
-#include "cairo-perf-timer.h"
+typedef struct _cairo_perf_timer_t cairo_perf_timer_t;
+
+/* timers */
+
+void
+timer_start (void);
+
+void
+timer_stop (void);
+
+double
+timer_elapsed (void);
+
+/* yield */
+
+void
+yield (void);
typedef double (*cairo_perf_func_t) (cairo_t *cr, int width, int height);
diff-tree 499a3a7c4772bb0f446f89a9c6e9430bd31c1218 (from df8cc10073b0cacd198eda5a24f2b2f61a0a7085)
Author: Carl Worth <cworth at cworth.org>
Date: Tue Sep 5 22:50:25 2006 -0700
perf: Remove unused alarm functions
diff --git a/perf/cairo-perf-timer-posix.c b/perf/cairo-perf-timer-posix.c
index 7c7ec19..685d7e5 100644
--- a/perf/cairo-perf-timer-posix.c
+++ b/perf/cairo-perf-timer-posix.c
@@ -64,35 +64,6 @@ timer_elapsed (void) {
return d;
}
-/* alarms */
-
-void
-alarm_handler (int signal) {
- if (signal == SIGALRM) {
- cairo_perf_alarm_expired = 1;
- }
-}
-
-void
-set_alarm (double seconds) {
- struct itimerval tr;
- long sec, usec;
-
- cairo_perf_alarm_expired = 0;
- signal (SIGALRM, alarm_handler);
-
- sec = floor (seconds);
- seconds -= sec;
- usec = seconds * 1e6;
-
- tr.it_interval.tv_sec = 0;
- tr.it_interval.tv_usec = 0;
- tr.it_value.tv_sec = sec;
- tr.it_value.tv_usec = usec;
-
- setitimer (ITIMER_REAL, &tr, NULL);
-}
-
/* yield */
void
diff --git a/perf/cairo-perf-timer-win32.c b/perf/cairo-perf-timer-win32.c
index 679abca..f0caa73 100644
--- a/perf/cairo-perf-timer-win32.c
+++ b/perf/cairo-perf-timer-win32.c
@@ -63,26 +63,6 @@ timer_elapsed (void) {
return d;
}
-/* alarms */
-
-void CALLBACK
-alarm_handler (void *closure, DWORD dwTimerLowValue, DWORD dwTimerHighValue) {
- cairo_perf_alarm_expired = 1;
-}
-
-HANDLE hTimer = NULL;
-void
-set_alarm (double seconds) {
- if (hTimer == NULL)
- hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
- cairo_perf_alarm_expired = 0;
-
- LARGE_INTEGER expTime;
- expTime.QuadPart = - (seconds * 10000000);
- if (!SetWaitableTimer (hTimer, &expTime, 0, alarm_handler, &cairo_perf_alarm_expired, FALSE))
- fprintf (stderr, "SetWaitableTimer failed!\n");
-}
-
/* yield */
void
diff --git a/perf/cairo-perf-timer.h b/perf/cairo-perf-timer.h
index b03ddce..fbe67a3 100644
--- a/perf/cairo-perf-timer.h
+++ b/perf/cairo-perf-timer.h
@@ -34,8 +34,6 @@ typedef struct _cairo_perf_timer_t cairo
/* timers */
-extern int alarm_expired;
-
void
timer_start (void);
@@ -45,14 +43,6 @@ timer_stop (void);
double
timer_elapsed (void);
-/* alarms */
-
-void
-alarm_handler (int signal);
-
-void
-set_alarm (double seconds);
-
/* yield */
void
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 32d96d3..9e51791 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -29,8 +29,6 @@
int cairo_perf_iterations = 100;
-int cairo_perf_alarm_expired = 0;
-
typedef struct _cairo_perf {
const char *name;
cairo_perf_func_t run;
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 7d7328a..d9e5ad8 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -32,8 +32,6 @@
#include "cairo-perf-timer.h"
-extern int cairo_perf_alarm_expired;
-
typedef double (*cairo_perf_func_t) (cairo_t *cr, int width, int height);
#define CAIRO_PERF_DECL(func) double func (cairo_t *cr, int width, int height)
diff-tree df8cc10073b0cacd198eda5a24f2b2f61a0a7085 (from 1bb6f9fb10dfdb59779ec159569ed6a44c4e8e5f)
Author: Benjamin Otte <in7y118 at public.uni-hamburg.de>
Date: Tue Sep 5 22:48:38 2006 -0700
perf: Make cairo_perf_timer structure private. Make timer functions void.
diff --git a/perf/cairo-perf-timer-posix.c b/perf/cairo-perf-timer-posix.c
index 1e9575f..7c7ec19 100644
--- a/perf/cairo-perf-timer-posix.c
+++ b/perf/cairo-perf-timer-posix.c
@@ -36,22 +36,30 @@
/* timers */
+static cairo_perf_timer_t tr;
+
+struct _cairo_perf_timer_t
+{
+ struct timeval start;
+ struct timeval stop;
+};
+
void
-timer_start (cairo_perf_timer_t *tr) {
- gettimeofday (&tr->start, NULL);
+timer_start (void) {
+ gettimeofday (&tr.start, NULL);
}
void
-timer_stop (cairo_perf_timer_t *tr) {
- gettimeofday (&tr->stop, NULL);
+timer_stop (void) {
+ gettimeofday (&tr.stop, NULL);
}
double
-timer_elapsed (cairo_perf_timer_t *tr) {
+timer_elapsed (void) {
double d;
- d = tr->stop.tv_sec - tr->start.tv_sec;
- d += (tr->stop.tv_usec - tr->start.tv_usec) / 1000000.0;
+ d = tr.stop.tv_sec - tr.start.tv_sec;
+ d += (tr.stop.tv_usec - tr.start.tv_usec) / 1000000.0;
return d;
}
diff --git a/perf/cairo-perf-timer-win32.c b/perf/cairo-perf-timer-win32.c
index ce813e0..679abca 100644
--- a/perf/cairo-perf-timer-win32.c
+++ b/perf/cairo-perf-timer-win32.c
@@ -34,24 +34,32 @@
/* timers */
+struct _cairo_perf_timer_t
+{
+ LARGE_INTEGER start;
+ LARGE_INTEGER stop;
+};
+
+static cairo_perf_timer_t tr;
+
void
-timer_start (cairo_perf_timer_t *tr) {
- QueryPerformanceCounter(&tr->start);
+timer_start (void) {
+ QueryPerformanceCounter(&tr.start);
}
void
-timer_stop (cairo_perf_timer_t *tr) {
- QueryPerformanceCounter(&tr->stop);
+timer_stop (void) {
+ QueryPerformanceCounter(&tr.stop);
}
double
-timer_elapsed (cairo_perf_timer_t *tr) {
+timer_elapsed (void) {
double d;
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
- d = (tr->stop.QuadPart - tr->start.QuadPart) / (double) freq.QuadPart;
+ d = (tr.stop.QuadPart - tr.start.QuadPart) / (double) freq.QuadPart;
return d;
}
diff --git a/perf/cairo-perf-timer.h b/perf/cairo-perf-timer.h
index 37a5184..b03ddce 100644
--- a/perf/cairo-perf-timer.h
+++ b/perf/cairo-perf-timer.h
@@ -30,29 +30,20 @@
#include "cairo-perf.h"
-typedef struct _cairo_perf_timer_t {
-#ifdef USE_WINAPI
- LARGE_INTEGER start;
- LARGE_INTEGER stop;
-#else
- struct timeval start;
- struct timeval stop;
-#endif
- long count;
-} cairo_perf_timer_t;
+typedef struct _cairo_perf_timer_t cairo_perf_timer_t;
/* timers */
extern int alarm_expired;
void
-timer_start (cairo_perf_timer_t *tr);
+timer_start (void);
void
-timer_stop (cairo_perf_timer_t *tr);
+timer_stop (void);
double
-timer_elapsed (cairo_perf_timer_t *tr);
+timer_elapsed (void);
/* alarms */
diff --git a/perf/paint.c b/perf/paint.c
index 97b8de5..858f15d 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -29,16 +29,15 @@ static double
do_paint (cairo_t *cr)
{
int i;
- cairo_perf_timer_t timer;
- timer_start (&timer);
+ timer_start ();
for (i=0; i < 3; i++)
cairo_paint (cr);
- timer_stop (&timer);
+ timer_stop ();
- return 1.0 / timer_elapsed (&timer);
+ return 1.0 / timer_elapsed ();
}
double
diff-tree 1bb6f9fb10dfdb59779ec159569ed6a44c4e8e5f (from bcb7863f00b4cfdf0985993067fc32d07b81540b)
Author: Benjamin Otte <in7y118 at public.uni-hamburg.de>
Date: Tue Sep 5 22:36:56 2006 -0700
perf: Add yield and fix double comparison
- add a yield () function that's called before every test. It reduced the std
dev slightly for me
- fix double comparisons to not just compare the integer part
diff --git a/perf/cairo-perf-timer-posix.c b/perf/cairo-perf-timer-posix.c
index 29fd3fb..1e9575f 100644
--- a/perf/cairo-perf-timer-posix.c
+++ b/perf/cairo-perf-timer-posix.c
@@ -28,6 +28,9 @@
#include <signal.h>
#include <sys/time.h>
#include <unistd.h>
+#ifdef _POSIX_PRIORITY_SCHEDULING
+#include <sched.h>
+#endif
#include "cairo-perf.h"
@@ -81,3 +84,12 @@ set_alarm (double seconds) {
setitimer (ITIMER_REAL, &tr, NULL);
}
+
+/* yield */
+
+void
+yield (void) {
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ sched_yield ();
+#endif
+}
diff --git a/perf/cairo-perf-timer-win32.c b/perf/cairo-perf-timer-win32.c
index c03256d..ce813e0 100644
--- a/perf/cairo-perf-timer-win32.c
+++ b/perf/cairo-perf-timer-win32.c
@@ -74,3 +74,10 @@ set_alarm (double seconds) {
if (!SetWaitableTimer (hTimer, &expTime, 0, alarm_handler, &cairo_perf_alarm_expired, FALSE))
fprintf (stderr, "SetWaitableTimer failed!\n");
}
+
+/* yield */
+
+void
+yield (void) {
+ SleepEx(0, TRUE);
+}
diff --git a/perf/cairo-perf-timer.h b/perf/cairo-perf-timer.h
index e934437..37a5184 100644
--- a/perf/cairo-perf-timer.h
+++ b/perf/cairo-perf-timer.h
@@ -62,4 +62,9 @@ alarm_handler (int signal);
void
set_alarm (double seconds);
+/* yield */
+
+void
+yield (void);
+
#endif
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 4cef046..32d96d3 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -102,7 +102,11 @@ compare_doubles (const void *_a, const v
const double *a = _a;
const double *b = _b;
- return *a - *b;
+ if (*a > *b)
+ return 1;
+ if (*a < *b)
+ return -1;
+ return 0;
}
static void
@@ -162,8 +166,10 @@ main (int argc, char *argv[])
size, size,
&target->closure);
cr = cairo_create (surface);
- for (k =0; k < cairo_perf_iterations; k++)
+ for (k =0; k < cairo_perf_iterations; k++) {
+ yield ();
rates[k] = perf->run (cr, size, size);
+ }
_compute_stats (rates, cairo_perf_iterations, &stats);
if (i==0 && j==0 && size == perf->min_size)
printf ("backend-content\ttest-size\trate\tstd dev.\titerations\n");
More information about the cairo-commit
mailing list