summaryrefslogtreecommitdiff
path: root/bench/bench.h
blob: 0eb578f03cd30ecdb963add83961e3d1d8886f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define rdtsc() ({ unsigned long a,d; asm volatile("rdtsc":"=a" (a), "=d" (d)); a; })

#define NREPS 1000

#define TIME(x,y) \
{ \
	int i,j;						\
	unsigned long bmin,bstart,bend;	\
	for (j=0; j<100; j++) {			\
		bmin = 100000;				\
		bstart = rdtsc();			\
		for (i=0; i<NREPS; i++)		\
			x;						\
		bend = rdtsc();				\
		bend -= bstart;				\
		if (bend < bmin)			\
			bmin = bend;			\
	}								\
	printf(y ": %ld cycles\n", bmin/NREPS); \
}