File: bitlock.c

package info (click to toggle)
glib2.0 2.78.4-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,048 kB
  • sloc: ansic: 495,608; xml: 17,404; python: 9,572; sh: 1,260; perl: 1,144; cpp: 487; makefile: 225
file content (39 lines) | stat: -rw-r--r-- 697 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <glib.h>

static void
test_bitlocks (void)
{
  guint64 start = g_get_monotonic_time ();
  gint lock = 0;
  guint i;
  guint n_iterations;

  n_iterations = g_test_perf () ? 100000000 : 1;

  for (i = 0; i < n_iterations; i++)
    {
      g_bit_lock (&lock, 0);
      g_bit_unlock (&lock, 0);
    }

  {
    gdouble elapsed;
    gdouble rate;

    elapsed = g_get_monotonic_time () - start;
    elapsed /= 1000000;
    rate = n_iterations / elapsed;

    g_test_maximized_result (rate, "iterations per second");
  }
}

int
main (int argc, char **argv)
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/bitlock/performance/uncontended", test_bitlocks);

  return g_test_run ();
}