source: git/factory/timing.h @ 9c6887

jengelh-datetimespielwiese
Last change on this file since 9c6887 was 9c6887, checked in by Hans Schoenemann <hannes@…>, 12 years ago
make include cstdio/cstdlib dependant on ifndef NOSTREAMIO
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id$ */
3
4/* It should be possible to include this file multiple times for different */
5/* settings of TIMING */
6
7#undef TIMING_START
8#undef TIMING_END
9#undef TIMING_END_AND_PRINT
10#undef TIMING_DEFINE_PRINT
11#undef TIMING_DEFINE_PRINTPROTO
12#undef TIMING_PRINT
13
14#ifdef TIMING
15#include <time.h>
16#if ! defined(WINNT) || defined(__GNUC__)
17#include <sys/times.h>
18#include <sys/param.h>
19#endif
20#ifndef NOSTREAMIO
21#ifdef HAVE_CSTDIO
22#include <cstdio>
23#else
24#include <stdio.h>
25#endif
26#endif
27
28// need to be adjusted on your machine:
29// the number of ticks per second: HZ
30#if ! defined (HZ) && defined (CLOCKS_PER_SEC)
31#define HZ CLOCKS_PER_SEC
32#endif
33#if ! defined (HZ)  && defined (CLK_TCK)
34#define HZ CLK_TCK
35#endif
36#ifndef HZ
37#ifdef sun
38#define HZ 60.0
39#else
40#define HZ 100.0
41#endif
42#endif
43
44#if defined(WINNT) && ! defined(__GNUC__)
45
46#define TIMING_START(t) { clock_t timing_ ## t ## _start, timing_ ## t ## _end; \
47  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) clock_t timing_ ## t ## _time; \
55void timing_print_ ## t ( char * msg ) { \
56  fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
57} \
58void timing_reset_ ## t () { \
59  timing_ ## t ## _time = 0; \
60}
61
62#else /* ! WINNT */
63
64#define TIMING_START(t) { struct tms timing_ ## t ## _start, timing_ ## t ## _end; \
65  times( &timing_ ## t ## _start );
66#define TIMING_END(t) times( &timing_ ## t ## _end ); \
67  timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; }
68#define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \
69  fprintf( stderr, "%s%.2f sec\n", msg, \
70           float( timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime ) / HZ ); \
71  timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; }
72#define TIMING_DEFINE_PRINT(t) long timing_ ## t ## _time; \
73void timing_print_ ## t ( char * msg ) { \
74  fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
75} \
76void timing_reset_ ## t () { \
77  timing_ ## t ## _time = 0; \
78}
79#endif /* ! WINNT */
80
81/* macros common to all platforms */
82#define TIMING_DEFINE_PRINTPROTO(t) void timing_print_ ## t ( char * ); \
83  void timing_reset_ ## t ();
84#define TIMING_PRINT(t, msg) timing_print_ ## t ( msg );
85#define TIMING_RESET(t) timing_reset_ ## t ();
86
87#else /* TIMING */
88#define TIMING_START(t)
89#define TIMING_END(t)
90#define TIMING_END_AND_PRINT(t, msg)
91#define TIMING_DEFINE_PRINT(t)
92#define TIMING_DEFINE_PRINTPROTO(t)
93#define TIMING_PRINT(t, msg)
94#define TIMING_RESET(t)
95#endif /* TIMING */
Note: See TracBrowser for help on using the repository browser.