My Project
Loading...
Searching...
No Matches
timing.h
Go to the documentation of this file.
1/* emacs edit mode for this file is -*- C++ -*- */
2
3/* It should be possible to include this file multiple times for different */
4/* settings of TIMING */
5
6#undef TIMING_START
7#undef TIMING_END
8#undef TIMING_END_AND_PRINT
9#undef TIMING_DEFINE_PRINT
10#undef TIMING_DEFINE_PRINTPROTO
11#undef TIMING_PRINT
12
13#ifdef TIMING
14#include <time.h>
15#if ! defined(WINNT) || defined(__GNUC__)
16#include <sys/times.h>
17#include <sys/param.h>
18#endif
19#ifndef NOSTREAMIO
20#ifdef HAVE_CSTDIO
21#include <cstdio>
22#else
23#include <stdio.h>
24#endif
25#endif
26
27// need to be adjusted on your machine:
28// the number of ticks per second: HZ
29#if ! defined (HZ) && defined (CLOCKS_PER_SEC)
30#define HZ CLOCKS_PER_SEC
31#endif
32#if ! defined (HZ) && defined (CLK_TCK)
33#define HZ CLK_TCK
34#endif
35#ifndef HZ
36#ifdef sun
37#define HZ 60.0
38#else
39#define HZ 100.0
40#endif
41#endif
42
43#if defined(WINNT) && ! defined(__GNUC__)
44
45#define TIMING_DEFINE(t) static clock_t timing_ ## t ## _start, timing_ ## t ## _end; \
46static clock_t timing_ ## t ## _time;
47#define TIMING_START(t) timing_ ## t ## _start = clock();
48#define TIMING_END(t) timing_ ## t ## _end = clock(); \
49timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start;
50#define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \
51 fprintf( stderr, "%s%.2f sec\n", msg, \
52 float( timing_ ## t ## _end - timing_ ## t ## _start ) / HZ ); \
53 timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start;
54#define TIMING_DEFINE_PRINT(t) static clock_t timing_ ## t ## _start, timing_ ## t ## _end; \
55static clock_t timing_ ## t ## _time; \
56static void timing_print_ ## t ( char * msg ) { \
57 fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
58} \
59static void timing_reset_ ## t () { \
60 timing_ ## t ## _time = 0; \
61}
62
63#else /* ! WINNT */
64
65#define TIMING_DEFINE(t) static struct tms timing_ ## t ## _start, timing_ ## t ## _end; \
66static long timing_ ## t ## _time;
67#define TIMING_START(t) times( &timing_ ## t ## _start );
68#define TIMING_END(t) times( &timing_ ## t ## _end ); \
69 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime;
70#define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \
71 fprintf( stderr, "%s%.2f sec\n", msg, \
72 float( timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime ) / HZ ); \
73 timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime;
74#define TIMING_DEFINE_PRINT(t) static struct tms timing_ ## t ## _start, timing_ ## t ## _end; \
75static long timing_ ## t ## _time; \
76static void timing_print_ ## t ( char * msg ) { \
77 fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
78} \
79static void timing_reset_ ## t () { \
80 timing_ ## t ## _time = 0; \
81}
82#endif /* ! WINNT */
83
84/* macros common to all platforms */
85#define TIMING_DEFINE_PRINTPROTO(t) void timing_print_ ## t ( char * ); \
86 void timing_reset_ ## t ();
87#define TIMING_PRINT(t, msg) timing_print_ ## t ( msg );
88#define TIMING_RESET(t) timing_reset_ ## t ();
89
90#else /* TIMING */
91#define TIMING_DEFINE(t)
92#define TIMING_START(t)
93#define TIMING_END(t)
94#define TIMING_END_AND_PRINT(t, msg)
95#define TIMING_DEFINE_PRINT(t)
96#define TIMING_DEFINE_PRINTPROTO(t)
97#define TIMING_PRINT(t, msg)
98#define TIMING_RESET(t)
99#endif /* TIMING */