Permalink
Browse files

tests: fix gobject performance tests

The performance tests use GTimer which internally uses
g_get_monotonic_time, which at least on Windows has
a pretty bad resolution: depending on the configuration
of the system, the wall clock time is updated as infrequently
as 64 times a second (which is approximately every 16ms).

For starters let's ask Windows for a higher timer
resolution (see g_get_monotonic_time comments in
gmain.c for more info).

However, it is still possible for min_elapsed to be zero.
In the common case this leads to a division by zero:
  factor = TARGET_ROUND_TIME / min_elapsed;

or when GLib has been compiled with -D__USE_MINGW_ANSI_STDIO=1,
factor ends up being inf, which is then passed into test
initialisation code which is trying to do the equivalent of:
  n = 10000 * inf
  data->objects = g_new (GObject *, n);

Work around these issues by setting min_elapsed = 0.001
whenever is would have been zero otherwise.
  • Loading branch information...
dieterv committed Oct 8, 2012
1 parent fdafd67 commit 53ba68c86e2c13f6abb941c939ef4223cd0efe3e
Showing with 15 additions and 0 deletions.
  1. +15 −0 tests/gobject/performance.c
@@ -22,6 +22,10 @@
#include <glib-object.h>
#include "testcommon.h"
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
#define WARM_UP_N_RUNS 50
#define ESTIMATE_ROUND_TIME_N_RUNS 5
#define DEFAULT_TEST_TIME 15 /* seconds */
@@ -107,6 +111,9 @@ run_test (PerformanceTest *test)
min_elapsed = MIN (min_elapsed, elapsed);
}
+ if (min_elapsed == 0)
+ min_elapsed = 0.001;
+
factor = TARGET_ROUND_TIME / min_elapsed;
if (verbose)
@@ -893,6 +900,10 @@ main (int argc,
GError *error = NULL;
int i;
+#ifdef G_OS_WIN32
+ timeBeginPeriod (1);
+#endif
+
context = g_option_context_new ("GObject performance tests");
g_option_context_add_main_entries (context, cmd_entries, NULL);
if (!g_option_context_parse (context, &argc, &argv, &error))
@@ -916,5 +927,9 @@ main (int argc,
run_test (&tests[i]);
}
+#ifdef G_OS_WIN32
+ timeEndPeriod (1);
+#endif
+
return 0;
}

0 comments on commit 53ba68c

Please sign in to comment.