diff options
author | Carl Worth <cworth@cworth.org> | 2006-08-31 11:02:20 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2006-08-31 11:02:20 -0700 |
commit | b9f629d54239c43eef4746293bcffd58ada442f2 (patch) | |
tree | 671f2ac1317389c079f3b1f736ad08b9034318ae /perf | |
parent | 13bcba68ae6f0d29b82def09e7a6e356266dc2e7 (diff) |
perf: Don't require a separate counter from the timer for perf loops.
Diffstat (limited to 'perf')
-rw-r--r-- | perf/cairo-perf.c | 14 | ||||
-rw-r--r-- | perf/cairo-perf.h | 58 | ||||
-rw-r--r-- | perf/paint.c | 7 | ||||
-rw-r--r-- | perf/timer-alarm-posix.c | 4 | ||||
-rw-r--r-- | perf/timer-alarm-win32.c | 6 | ||||
-rw-r--r-- | perf/timer-alarm.h | 11 |
6 files changed, 46 insertions, 54 deletions
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c index e69bb2bf..780cc889 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_t *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 75ab975b..23c377a3 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 41983da7..ce4da7d5 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 7fe04517..32486d1b 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 fc1ad90c..e75f1d20 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 942bc282..847c1ceb 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 |