File: bench.h

package info (click to toggle)
sfs 1%3A0.8-0%2Bpre20060720.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,668 kB
  • ctags: 14,317
  • sloc: cpp: 78,358; ansic: 15,494; sh: 9,540; yacc: 786; makefile: 706; perl: 676; lex: 553; python: 146; sed: 70
file content (45 lines) | stat: -rw-r--r-- 979 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45

#if defined (__OpenBSD__) || defined (__NetBSD__)
# ifndef USE_PCTR
#  define  USE_PCTR 1
# endif /* !USE_PCTR */
#endif /* __OpenBSD__ */

#if USE_PCTR
#include <machine/pctr.h>
#define get_time() rdtsc ()
#define TIME_LABEL "cycles"
#else /* !USE_PCTR */
inline u_int64_t
get_time ()
{
  timeval tv;
  gettimeofday (&tv, NULL);
  return (u_int64_t) tv.tv_sec * 1000000 + tv.tv_usec;
}
#define TIME_LABEL "usec"
#endif /* !USE_PCTR */


#define BENCH(iter, code)					\
{								\
  u_int64_t __v;						\
  { code; }							\
  { code; }							\
  __v = get_time ();						\
  for (u_int i = 0; i < iter; i++) {				\
    code;							\
  }								\
  __v = get_time () - __v;					\
  warn ("%s: %" U64F "d " TIME_LABEL " (%" U64F "d tot)\n",	\
        #code, __v / iter, __v);				\
}

#define TIME(code)					\
{							\
  u_int64_t __v;					\
  __v = get_time ();					\
  { code; }						\
  __v = get_time () - __v;				\
  warn ("%s: %" U64F "d " TIME_LABEL "\n", #code, __v);	\
}