[cairo-commit] perf/cairo-perf.c perf/cairo-perf.h perf/paint.c

Carl Worth cworth at kemper.freedesktop.org
Thu Aug 31 17:44:12 PDT 2006


 perf/cairo-perf.c |   29 +++++++++++++++++++----------
 perf/cairo-perf.h |   30 ------------------------------
 perf/paint.c      |   12 +++++++-----
 3 files changed, 26 insertions(+), 45 deletions(-)

New commits:
diff-tree 2fa0228d63713f6274ca3228f236f1ee362ba11f (from 6ae6d91c0c3a2f8fdff39c1c84fbef3aa45bf958)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Aug 31 17:43:40 2006 -0700

    Two big improvements to bring the std. deviation down to where we want it.
    
    1. Remove all the alarm/signal code, which just isn't doing what we want for some reason.
       Instead, for now we'll simply run for a fixed number of iterations, (perhaps we
       can tune that per test later).
    
    2. Before computing mean and stdandard deviation of runs, sort them all and discard the
       top and bottom 20% of the values.
    
    Now the standard deviation for the paint test is generally 2% or less.

diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index c750381..4cef046 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -27,9 +27,7 @@
 
 #include "cairo-perf.h"
 
-double cairo_perf_duration = 1;
-
-int cairo_perf_iterations = 10;
+int cairo_perf_iterations = 100;
 
 int cairo_perf_alarm_expired = 0;
 
@@ -98,20 +96,34 @@ typedef struct _stats
     double std_dev;
 } stats_t;
 
+static int
+compare_doubles (const void *_a, const void *_b)
+{
+    const double *a = _a;
+    const double *b = _b;
+
+    return *a - *b;
+}
+
 static void
 _compute_stats (double *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);
+
+    num_values -= 2 * chop;
 
     sum = 0.0;
-    for (i = 0; i < num_values; i++)
+    for (i = chop; i < chop + num_values; i++)
 	sum += values[i];
 
     stats->mean = sum / num_values;
 
     sum = 0.0;
-    for (i = 0; i < num_values; i++) {
+    for (i = chop; i < chop + num_values; i++) {
 	delta = values[i] - stats->mean;
 	sum += delta * delta;
     }
@@ -133,9 +145,6 @@ main (int argc, char *argv[])
     double *rates;
     stats_t stats;
 
-    if (getenv("CAIRO_PERF_DURATION"))
-	cairo_perf_duration = strtod(getenv("CAIRO_PERF_DURATION"), NULL);
-
     if (getenv("CAIRO_PERF_ITERATIONS"))
 	cairo_perf_iterations = strtol(getenv("CAIRO_PERF_ITERATIONS"), NULL, 0);
 
@@ -170,7 +179,7 @@ main (int argc, char *argv[])
 }
 
 cairo_perf_t perfs[] = {
-    { "paint", paint, 32, 1024 },
-    { "paint_alpha", paint_alpha, 32, 1024 },
+    { "paint", paint, 64, 512 },
+    { "paint_alpha", paint_alpha, 64, 512 },
     { NULL }
 };
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index aad76e9..7d7328a 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -32,38 +32,8 @@
 
 #include "cairo-perf-timer.h"
 
-extern double cairo_perf_duration;
 extern int cairo_perf_alarm_expired;
 
-#if CAIRO_HAS_WIN32_SURFACE
-/* Windows needs a SleepEx to put the thread into an alertable state,
- * such that the timer expiration callback can fire.  I can't figure
- * out how to do an async timer.  On a quiet system, this doesn't
- * seem to significantly affect the results.
- */
-# define CAIRO_PERF_LOOP_INIT(timervar)  do {	\
-    timervar.count = 0;				\
-    timer_start (&(timervar));			\
-    set_alarm (cairo_perf_duration);		\
-    while (! cairo_perf_alarm_expired) {	\
-        SleepEx(0, TRUE)
-#else
-# define CAIRO_PERF_LOOP_INIT(timervar)  do {	\
-    timervar.count = 0;				\
-    timer_start (&(timervar));			\
-    set_alarm (cairo_perf_duration);		\
-    while (! cairo_perf_alarm_expired) {
-#endif
-
-#define CAIRO_PERF_LOOP_FINI(timervar)		\
-    (timervar).count++;				\
-    }						\
-    timer_stop (&(timervar));			\
-    } while (0)
-
-#define CAIRO_PERF_LOOP_RATE(timervar)		\
-    ((timervar).count) / timer_elapsed (&(timervar))
-
 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 --git a/perf/paint.c b/perf/paint.c
index 2f47d74..97b8de5 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -28,15 +28,17 @@
 static double
 do_paint (cairo_t *cr)
 {
+    int i;
     cairo_perf_timer_t timer;
 
-    CAIRO_PERF_LOOP_INIT (timer);
-    {
+    timer_start (&timer);
+
+    for (i=0; i < 3; i++)
 	cairo_paint (cr);
-    }
-    CAIRO_PERF_LOOP_FINI (timer);
 
-    return CAIRO_PERF_LOOP_RATE (timer);
+    timer_stop (&timer);
+
+    return 1.0 / timer_elapsed (&timer);
 }
 
 double


More information about the cairo-commit mailing list