mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-31 21:03:10 +02:00
tests: Allow bitlock performance test to be smoketested
Allow it to be run with a reduced iteration count when not run as `-m perf`, in order to check that the test still works. Previously it would do nothing when run without `-m perf`. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
6f435e40cd
commit
419f882952
@ -1,15 +1,16 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#define ITERATIONS 100000000
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_bitlocks (void)
|
test_bitlocks (void)
|
||||||
{
|
{
|
||||||
guint64 start = g_get_monotonic_time ();
|
guint64 start = g_get_monotonic_time ();
|
||||||
gint lock = 0;
|
gint lock = 0;
|
||||||
gint i;
|
guint i;
|
||||||
|
guint n_iterations;
|
||||||
|
|
||||||
for (i = 0; i < ITERATIONS; i++)
|
n_iterations = g_test_perf () ? 100000000 : 1;
|
||||||
|
|
||||||
|
for (i = 0; i < n_iterations; i++)
|
||||||
{
|
{
|
||||||
g_bit_lock (&lock, 0);
|
g_bit_lock (&lock, 0);
|
||||||
g_bit_unlock (&lock, 0);
|
g_bit_unlock (&lock, 0);
|
||||||
@ -21,7 +22,7 @@ test_bitlocks (void)
|
|||||||
|
|
||||||
elapsed = g_get_monotonic_time () - start;
|
elapsed = g_get_monotonic_time () - start;
|
||||||
elapsed /= 1000000;
|
elapsed /= 1000000;
|
||||||
rate = ITERATIONS / elapsed;
|
rate = n_iterations / elapsed;
|
||||||
|
|
||||||
g_test_maximized_result (rate, "iterations per second");
|
g_test_maximized_result (rate, "iterations per second");
|
||||||
}
|
}
|
||||||
@ -32,8 +33,7 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
if (g_test_perf ())
|
g_test_add_func ("/bitlock/performance/uncontended", test_bitlocks);
|
||||||
g_test_add_func ("/bitlock/performance/uncontended", test_bitlocks);
|
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user