source: git/factory/timing.h @ 2df361

fieker-DuValspielwiese
Last change on this file since 2df361 was 2df361, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: made functions and variables for timings static
  • Property mode set to 100644
File size: 3.0 KB
Line 
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_START(t) timing_ ## t ## _start = clock();
46#define TIMING_END(t) timing_ ## t ## _end = clock(); \
47timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start;
48#define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \
49  fprintf( stderr, "%s%.2f sec\n", msg, \
50           float( timing_ ## t ## _end - timing_ ## t ## _start ) / HZ ); \
51  timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start;
52#define TIMING_DEFINE_PRINT(t) static clock_t timing_ ## t ## _start, timing_ ## t ## _end; \
53static clock_t timing_ ## t ## _time; \
54static void timing_print_ ## t ( char * msg ) { \
55  fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
56} \
57static void timing_reset_ ## t () { \
58  timing_ ## t ## _time = 0; \
59}
60
61#else /* ! WINNT */
62
63#define TIMING_START(t) times( &timing_ ## t ## _start );
64#define TIMING_END(t) times( &timing_ ## t ## _end ); \
65  timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime;
66#define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \
67  fprintf( stderr, "%s%.2f sec\n", msg, \
68           float( timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime ) / HZ ); \
69  timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime;
70#define TIMING_DEFINE_PRINT(t) static struct tms timing_ ## t ## _start, timing_ ## t ## _end; \
71static long timing_ ## t ## _time; \
72static void timing_print_ ## t ( char * msg ) { \
73  fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
74} \
75static void timing_reset_ ## t () { \
76  timing_ ## t ## _time = 0; \
77}
78#endif /* ! WINNT */
79
80/* macros common to all platforms */
81#define TIMING_DEFINE_PRINTPROTO(t) void timing_print_ ## t ( char * ); \
82  void timing_reset_ ## t ();
83#define TIMING_PRINT(t, msg) timing_print_ ## t ( msg );
84#define TIMING_RESET(t) timing_reset_ ## t ();
85
86#else /* TIMING */
87#define TIMING_START(t)
88#define TIMING_END(t)
89#define TIMING_END_AND_PRINT(t, msg)
90#define TIMING_DEFINE_PRINT(t)
91#define TIMING_DEFINE_PRINTPROTO(t)
92#define TIMING_PRINT(t, msg)
93#define TIMING_RESET(t)
94#endif /* TIMING */
Note: See TracBrowser for help on using the repository browser.