make.tmpl: add missing compiler attribute to build_progs
[AROS.git] / test / benchmarks / clib / benchmark.h
blob7cde3fbc0aa0139ab6caf283046c7e5131e9e347
1 /*
2 Copyright © 2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <boost/preprocessor/repetition/repeat.hpp>
7 #include <sys/time.h>
8 #include <stdlib.h>
9 #include <stdio.h>
11 #define TIMER(name) \
12 struct timeval name ## _start; \
13 struct timeval name ## _stop
15 #define START(name) gettimeofday(& name ## _start, NULL);
17 #define STOP(name) gettimeofday(& name ## _stop, NULL);
19 #define ELAPSED(name) ((double)(((name ## _stop.tv_sec * 1000000) + name ## _stop.tv_usec) - ((name ## _start.tv_sec * 1000000) + name ## _start.tv_usec))/1000000.0)
21 #define BENCHMARK_UNIVERSAL(name, count, bufsize) \
22 TIMER(name); \
23 START(name); \
24 long name ## _i; \
25 for(name ## _i = 0; name ## _i < count/100; name ## _i++) { \
26 BOOST_PP_REPEAT(100, BENCHMARK,name ## _i); \
27 } \
28 STOP(name);
30 #define BENCHMARK_OPERATION(name, count) \
31 BENCHMARK_UNIVERSAL(name, count, 1); \
32 printf(#name " %.2lf operations/s\n", 1.0 * count / ELAPSED(name));
35 #define BENCHMARK_BUFFER(name, count, bufsize) \
36 BENCHMARK_UNIVERSAL(name, count, bufsize) \
37 printf(#name " %.2lf bytes/s\n", 1.0 * bufsize * count / ELAPSED(name));