[cairo-commit] 2 commits - perf/cairo-perf.c perf/cairo-perf.h perf/Makefile.am perf/paint.c perf/timer-alarm.h perf/timer-alarm-posix.c perf/timer-alarm-win32.c perf/timing.c perf/timing.h

Carl Worth cworth at kemper.freedesktop.org
Thu Aug 31 11:02:29 PDT 2006


 perf/Makefile.am         |    2 -
 perf/cairo-perf.c        |   34 +++++++++++++++++++----
 perf/cairo-perf.h        |   59 +++++++++++++++++++++++++++++++++++-----
 perf/paint.c             |    8 ++---
 perf/timer-alarm-posix.c |    6 ++--
 perf/timer-alarm-win32.c |    9 ++----
 perf/timer-alarm.h       |   11 -------
 perf/timing.c            |   56 --------------------------------------
 perf/timing.h            |   68 -----------------------------------------------
 9 files changed, 89 insertions(+), 164 deletions(-)

New commits:
diff-tree b9f629d54239c43eef4746293bcffd58ada442f2 (from 13bcba68ae6f0d29b82def09e7a6e356266dc2e7)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Aug 31 11:02:20 2006 -0700

    perf: Don't require a separate counter from the timer for perf loops.

diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index e69bb2b..780cc88 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -29,7 +29,7 @@
 
 int cairo_perf_duration = -1;
 
-int alarm_expired = 0;
+int cairo_perf_alarm_expired = 0;
 
 typedef struct _cairo_perf {
     const char *name;
@@ -81,27 +81,21 @@ target_is_measurable (cairo_test_target_
 }
 
 void
-start_timing (bench_timer_t *tr, long *count) {
+start_timing (bench_timer_t *tr) {
     if (cairo_perf_duration == -1) {
         if (getenv("CAIRO_PERF_DURATION"))
             cairo_perf_duration = strtol(getenv("CAIRO_PERF_DURATION"), NULL, 0);
         else
             cairo_perf_duration = 5;
     }
-    *count = 0;
+    tr->count = 0;
     timer_start (tr);
     set_alarm (cairo_perf_duration);
 }
 
 void
-stop_timing (bench_timer_t *tr, long count) {
+stop_timing (bench_timer_t *tr) {
     timer_stop (tr);
-    tr->count = count;
-}
-
-double
-timing_result (bench_timer_t *tr) {
-    return tr->count / timer_elapsed (tr);
 }
 
 int
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 75ab975..23c377a 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -30,42 +30,52 @@
 
 #include "cairo-boilerplate.h"
 
-#include "timer-alarm.h"
+typedef struct {
+#ifdef USE_WINAPI
+    LARGE_INTEGER start;
+    LARGE_INTEGER stop;
+#else
+    struct timeval start;
+    struct timeval stop;
+#endif
+    long count;
+} bench_timer_t;
 
-extern int cairo_perf_duration;
-extern int alarm_expired;
+#include "timer-alarm.h"
 
 void
-start_timing (bench_timer_t *tr, long *count);
+start_timing (bench_timer_t *tr);
 
 void
-stop_timing (bench_timer_t *tr, long count);
+stop_timing (bench_timer_t *tr);
 
-double
-timing_result (bench_timer_t *tr);
+extern int 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 PERF_LOOP_INIT(timervar,countvar)  do {     \
-    countvar = 0;                                    \
-    start_timing(&(timervar), &(countvar));          \
-    while (!alarm_expired) {                         \
-        SleepEx(0, TRUE);
+/* 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 PERF_LOOP_INIT(timervar)  do {              \
+    start_timing(&(timervar));                       \
+    while (! cairo_perf_alarm_expired) {             \
+        SleepEx(0, TRUE)
 #else
-# define PERF_LOOP_INIT(timervar,countvar)  do {     \
-    countvar = 0;                                    \
-    start_timing(&(timervar), &(countvar));          \
-    while (!alarm_expired) {
+# define PERF_LOOP_INIT(timervar)  do {              \
+    start_timing(&(timervar));                       \
+    while (! cairo_perf_alarm_expired) {
 #endif
 
-#define PERF_LOOP_FINI(timervar,countvar)       \
-    (countvar)++;                               \
+#define PERF_LOOP_FINI(timervar)                \
+    (timervar).count++;                         \
     }                                           \
-    stop_timing (&(timervar), (countvar));      \
-    } while (0);
+    stop_timing (&(timervar));                  \
+    } while (0)
+
+#define PERF_LOOP_RATE(timervar)		\
+    ((timervar).count) / timer_elapsed (&(timervar))
 
 typedef void (*cairo_perf_func_t) (cairo_t *cr, int width, int height);
 
diff --git a/perf/paint.c b/perf/paint.c
index 41983da..ce4da7d 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -41,13 +41,12 @@ void
 paint (cairo_t *cr, int width, int height)
 {
     bench_timer_t timer;
-    long count;
 
-    PERF_LOOP_INIT (timer, count);
+    PERF_LOOP_INIT (timer);
     {
 	cairo_paint (cr);
     }
-    PERF_LOOP_FINI (timer, count);
+    PERF_LOOP_FINI (timer);
 
-    printf ("Rate: %g\n", timing_result (&timer));
+    printf ("Rate: %g\n", PERF_LOOP_RATE (timer));
 }
diff --git a/perf/timer-alarm-posix.c b/perf/timer-alarm-posix.c
index 7fe0451..32486d1 100644
--- a/perf/timer-alarm-posix.c
+++ b/perf/timer-alarm-posix.c
@@ -58,13 +58,13 @@ timer_elapsed (bench_timer_t *tr) {
 void
 alarm_handler (int signal) {
     if (signal == SIGALRM) {
-        alarm_expired = 1;
+        cairo_perf_alarm_expired = 1;
     }
 }
 
 void
 set_alarm (int seconds) {
-    alarm_expired = 0;
+    cairo_perf_alarm_expired = 0;
     signal (SIGALRM, alarm_handler);
     alarm (seconds);
 }
diff --git a/perf/timer-alarm-win32.c b/perf/timer-alarm-win32.c
index fc1ad90..e75f1d2 100644
--- a/perf/timer-alarm-win32.c
+++ b/perf/timer-alarm-win32.c
@@ -59,7 +59,7 @@ timer_elapsed (bench_timer_t *tr) {
 
 void CALLBACK
 alarm_handler (void *closure, DWORD dwTimerLowValue, DWORD dwTimerHighValue) {
-    alarm_expired = 1;
+    cairo_perf_alarm_expired = 1;
 }
 
 HANDLE hTimer = NULL;
@@ -67,10 +67,10 @@ void
 set_alarm (int seconds) {
     if (hTimer == NULL)
         hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
-    alarm_expired = 0;
+    cairo_perf_alarm_expired = 0;
 
     LARGE_INTEGER expTime;
     expTime.QuadPart = - (seconds * 10000000);
-    if (!SetWaitableTimer (hTimer, &expTime, 0, alarm_handler, &alarm_expired, FALSE))
+    if (!SetWaitableTimer (hTimer, &expTime, 0, alarm_handler, &cairo_perf_alarm_expired, FALSE))
         fprintf (stderr, "SetWaitableTimer failed!\n");
 }
diff --git a/perf/timer-alarm.h b/perf/timer-alarm.h
index 942bc28..847c1ce 100644
--- a/perf/timer-alarm.h
+++ b/perf/timer-alarm.h
@@ -32,17 +32,6 @@
 
 /* timers */
 
-typedef struct {
-#ifdef USE_WINAPI
-    LARGE_INTEGER start;
-    LARGE_INTEGER stop;
-#else
-    struct timeval start;
-    struct timeval stop;
-#endif
-    long count;
-} bench_timer_t;
-
 extern int alarm_expired;
 
 void
diff-tree 13bcba68ae6f0d29b82def09e7a6e356266dc2e7 (from a60ed68daebc15e87ededbca80211508f624bcb6)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Aug 31 10:39:24 2006 -0700

    perf: Collapse timing.[ch] down into cairo-perf.[ch]

diff --git a/perf/Makefile.am b/perf/Makefile.am
index f9124c5..d5412aa 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -16,8 +16,6 @@ noinst_PROGRAMS = cairo-perf
 cairo_perf_SOURCES =	\
 	cairo-perf.c	\
 	cairo-perf.h	\
-	timing.c	\
-	timing.h	\
 	timer-alarm.h	\
 	paint.c
 
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 14f2d57..e69bb2b 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -1,4 +1,5 @@
 /*
+ * Copyright © 2006 Mozilla Corporation
  * Copyright © 2006 Red Hat, Inc.
  *
  * Permission to use, copy, modify, distribute, and sell this software
@@ -6,26 +7,29 @@
  * 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
- * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * the authors not be used in advertising or publicity pertaining to
  * distribution of the software without specific, written prior
- * permission. Red Hat, Inc. makes no representations about the
+ * 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.
  *
- * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * 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.
  *
- * Author: Carl D. Worth <cworth at cworth.org>
+ * Authors: Vladimir Vukicevic <vladimir at pobox.com>
+ *          Carl Worth <cworth at cworth.org>
  */
 
 #include "cairo-perf.h"
 
-unsigned int iterations = 0;
+int cairo_perf_duration = -1;
+
+int alarm_expired = 0;
 
 typedef struct _cairo_perf {
     const char *name;
@@ -76,6 +80,30 @@ target_is_measurable (cairo_test_target_
     }
 }
 
+void
+start_timing (bench_timer_t *tr, long *count) {
+    if (cairo_perf_duration == -1) {
+        if (getenv("CAIRO_PERF_DURATION"))
+            cairo_perf_duration = strtol(getenv("CAIRO_PERF_DURATION"), NULL, 0);
+        else
+            cairo_perf_duration = 5;
+    }
+    *count = 0;
+    timer_start (tr);
+    set_alarm (cairo_perf_duration);
+}
+
+void
+stop_timing (bench_timer_t *tr, long count) {
+    timer_stop (tr);
+    tr->count = count;
+}
+
+double
+timing_result (bench_timer_t *tr) {
+    return tr->count / timer_elapsed (tr);
+}
+
 int
 main (int argc, char *argv[])
 {
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 3fc235f..75ab975 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -1,4 +1,5 @@
 /*
+ * Copyright © 2006 Mozilla Corporation
  * Copyright © 2006 Red Hat, Inc.
  *
  * Permission to use, copy, modify, distribute, and sell this software
@@ -6,21 +7,22 @@
  * 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
- * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * the authors not be used in advertising or publicity pertaining to
  * distribution of the software without specific, written prior
- * permission. Red Hat, Inc. makes no representations about the
+ * 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.
  *
- * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * 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.
  *
- * Author: Carl D. Worth <cworth at cworth.org>
+ * Authors: Vladimir Vukicevic <vladimir at pobox.com>
+ *          Carl Worth <cworth at cworth.org>
  */
 
 #ifndef _CAIRO_PERF_H_
@@ -28,9 +30,42 @@
 
 #include "cairo-boilerplate.h"
 
-#include "timing.h"
+#include "timer-alarm.h"
 
-extern unsigned int iterations;
+extern int cairo_perf_duration;
+extern int alarm_expired;
+
+void
+start_timing (bench_timer_t *tr, long *count);
+
+void
+stop_timing (bench_timer_t *tr, long count);
+
+double
+timing_result (bench_timer_t *tr);
+
+#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 PERF_LOOP_INIT(timervar,countvar)  do {     \
+    countvar = 0;                                    \
+    start_timing(&(timervar), &(countvar));          \
+    while (!alarm_expired) {                         \
+        SleepEx(0, TRUE);
+#else
+# define PERF_LOOP_INIT(timervar,countvar)  do {     \
+    countvar = 0;                                    \
+    start_timing(&(timervar), &(countvar));          \
+    while (!alarm_expired) {
+#endif
+
+#define PERF_LOOP_FINI(timervar,countvar)       \
+    (countvar)++;                               \
+    }                                           \
+    stop_timing (&(timervar), (countvar));      \
+    } while (0);
 
 typedef void (*cairo_perf_func_t) (cairo_t *cr, int width, int height);
 
diff --git a/perf/paint.c b/perf/paint.c
index c4233df..41983da 100644
--- a/perf/paint.c
+++ b/perf/paint.c
@@ -46,7 +46,6 @@ paint (cairo_t *cr, int width, int heigh
     PERF_LOOP_INIT (timer, count);
     {
 	cairo_paint (cr);
-	iterations++;
     }
     PERF_LOOP_FINI (timer, count);
 
diff --git a/perf/timer-alarm-posix.c b/perf/timer-alarm-posix.c
index 161d1be..7fe0451 100644
--- a/perf/timer-alarm-posix.c
+++ b/perf/timer-alarm-posix.c
@@ -29,7 +29,7 @@
 #include <sys/time.h>
 #include <unistd.h>
 
-#include "timing.h"
+#include "cairo-perf.h"
 
 /* timers */
 
diff --git a/perf/timer-alarm-win32.c b/perf/timer-alarm-win32.c
index 70fc8a9..fc1ad90 100644
--- a/perf/timer-alarm-win32.c
+++ b/perf/timer-alarm-win32.c
@@ -56,9 +56,6 @@ timer_elapsed (bench_timer_t *tr) {
 }
 
 /* alarms */
-int test_seconds = -1;
-
-int alarm_expired = 0;
 
 void CALLBACK
 alarm_handler (void *closure, DWORD dwTimerLowValue, DWORD dwTimerHighValue) {
diff --git a/perf/timing.c b/perf/timing.c
deleted file mode 100644
index 20318d8..0000000
--- a/perf/timing.c
+++ /dev/null
@@ -1,56 +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 "timing.h"
-
-int cairo_perf_duration = -1;
-
-int alarm_expired = 0;
-
-void
-start_timing (bench_timer_t *tr, long *count) {
-    if (cairo_perf_duration == -1) {
-        if (getenv("CAIRO_PERF_DURATION"))
-            cairo_perf_duration = strtol(getenv("CAIRO_PERF_DURATION"), NULL, 0);
-        else
-            cairo_perf_duration = 5;
-    }
-    *count = 0;
-    timer_start (tr);
-    set_alarm (cairo_perf_duration);
-}
-
-void
-stop_timing (bench_timer_t *tr, long count) {
-    timer_stop (tr);
-    tr->count = count;
-}
-
-double
-timing_result (bench_timer_t *tr) {
-    return tr->count / timer_elapsed (tr);
-}
diff --git a/perf/timing.h b/perf/timing.h
deleted file mode 100644
index 9b73438..0000000
--- a/perf/timing.h
+++ /dev/null
@@ -1,68 +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 _TIMING_H_
-#define _TIMING_H_
-
-#include "timer-alarm.h"
-
-extern int cairo_perf_duration;
-extern int alarm_expired;
-
-void
-start_timing (bench_timer_t *tr, long *count);
-
-void
-stop_timing (bench_timer_t *tr, long count);
-
-double
-timing_result (bench_timer_t *tr);
-
-#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 PERF_LOOP_INIT(timervar,countvar)  do {     \
-    countvar = 0;                                    \
-    start_timing(&(timervar), &(countvar));          \
-    while (!alarm_expired) {                         \
-        SleepEx(0, TRUE);
-#else
-# define PERF_LOOP_INIT(timervar,countvar)  do {     \
-    countvar = 0;                                    \
-    start_timing(&(timervar), &(countvar));          \
-    while (!alarm_expired) {
-#endif
-
-#define PERF_LOOP_FINI(timervar,countvar)       \
-    (countvar)++;                               \
-    }                                           \
-    stop_timing (&(timervar), (countvar));      \
-    } while (0);
-
-#endif


More information about the cairo-commit mailing list