Add test cycles per loop
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Sun, 13 Jun 2010 23:55:41 +0000 (19:55 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Sun, 13 Jun 2010 23:55:41 +0000 (19:55 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/Makefile.am
tests/test_cycles_per_loop.c [new file with mode: 0644]

index e0bbf464853daa10e7a92d8e130dad7729e27f69..0ff6b3ed08e8e8527ded206924556274250cdd35 100644 (file)
@@ -12,7 +12,7 @@ noinst_PROGRAMS = test_urcu test_urcu_dynamic_link test_urcu_timing \
         test_urcu_mb_gc test_qsbr_gc test_qsbr_lgc test_urcu_signal_lgc \
         test_urcu_mb_lgc test_qsbr_dynamic_link test_urcu_defer \
         test_uatomic test_urcu_assign test_urcu_assign_dynamic_link \
-        test_urcu_bp test_urcu_bp_dynamic_link
+        test_urcu_bp test_urcu_bp_dynamic_link test_cycles_per_loop
 noinst_HEADERS = rcutorture.h
 
 if COMPAT_ARCH
@@ -139,6 +139,8 @@ test_urcu_defer_SOURCES = test_urcu_defer.c $(URCU_DEFER)
 
 test_uatomic_SOURCES = test_uatomic.c $(COMPAT)
 
+test_cycles_per_loop_SOURCES = test_cycles_per_loop.c
+
 test_urcu_assign_SOURCES = test_urcu_assign.c $(URCU)
 
 test_urcu_assign_dynamic_link_SOURCES = test_urcu_assign.c $(URCU)
diff --git a/tests/test_cycles_per_loop.c b/tests/test_cycles_per_loop.c
new file mode 100644 (file)
index 0000000..64b160b
--- /dev/null
@@ -0,0 +1,21 @@
+#include <urcu/arch.h>
+#include <stdio.h>
+
+#define NR_LOOPS 1000000UL
+
+static inline void loop_sleep(unsigned long l)
+{
+       while(l-- != 0)
+               cpu_relax();
+}
+
+int main()
+{
+       cycles_t time1, time2;
+
+       time1 = get_cycles();
+       loop_sleep(NR_LOOPS);
+       time2 = get_cycles();
+       printf("CPU clock cycles per loop: %g\n", (time2 - time1) /
+                                                 (double)NR_LOOPS);
+}
This page took 0.025999 seconds and 4 git commands to generate.