File: test_cycles_per_loop.c

package info (click to toggle)
liburcu 0.6.7-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,784 kB
  • sloc: ansic: 11,459; sh: 10,312; makefile: 184
file content (22 lines) | stat: -rw-r--r-- 375 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <urcu/arch.h>
#include <stdio.h>

#define NR_LOOPS 1000000UL

static inline void loop_sleep(unsigned long l)
{
	while(l-- != 0)
		caa_cpu_relax();
}

int main()
{
	cycles_t time1, time2;

	time1 = caa_get_cycles();
	loop_sleep(NR_LOOPS);
	time2 = caa_get_cycles();
	printf("CPU clock cycles per loop: %g\n", (time2 - time1) /
						  (double)NR_LOOPS);
	return 0;
}