source: git/factory/libfac/factor/timing.h @ 16055bd

jengelh-datetimespielwiese
Last change on this file since 16055bd was 16055bd, checked in by Martin Lee <martinlee84@…>, 11 years ago
chg: move libfac into factory
  • Property mode set to 100644
File size: 2.9 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) { clock_t timing_ ## t ## _start, timing_ ## t ## _end; \
46  timing_ ## t ## _start = clock();
47#define TIMING_END(t) timing_ ## t ## _end = clock(); \
48timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; }
49#define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \
50  fprintf( stderr, "%s%.2f sec\n", msg, \
51           float( timing_ ## t ## _end - timing_ ## t ## _start ) / HZ ); \
52  timing_ ## t ## _time += timing_ ## t ## _end - timing_ ## t ## _start; }
53#define TIMING_DEFINE_PRINT(t) clock_t timing_ ## t ## _time; \
54void timing_print_ ## t ( char * msg ) { \
55  fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
56} \
57void timing_reset_ ## t () { \
58  timing_ ## t ## _time = 0; \
59}
60
61#else /* ! WINNT */
62
63#define TIMING_START(t) { struct tms timing_ ## t ## _start, timing_ ## t ## _end; \
64  times( &timing_ ## t ## _start );
65#define TIMING_END(t) times( &timing_ ## t ## _end ); \
66  timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; }
67#define TIMING_END_AND_PRINT(t, msg) times( &timing_ ## t ## _end ); \
68  fprintf( stderr, "%s%.2f sec\n", msg, \
69           float( timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime ) / HZ ); \
70  timing_ ## t ## _time += timing_ ## t ## _end.tms_utime - timing_ ## t ## _start.tms_utime; }
71#define TIMING_DEFINE_PRINT(t) long timing_ ## t ## _time; \
72void timing_print_ ## t ( char * msg ) { \
73  fprintf( stderr, "%s%.2f sec\n", msg, float(timing_ ## t ## _time) / HZ ); \
74} \
75void 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.