ARB
PerfMeter.h
Go to the documentation of this file.
1 // ================================================================ //
2 // //
3 // File : PerfMeter.h //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in February 2015 //
7 // http://www.arb-home.de/ //
8 // //
9 // ================================================================ //
10 
11 #ifndef PERFMETER_H
12 #define PERFMETER_H
13 
14 #ifndef _TIME_H
15 #include <time.h>
16 #endif
17 #ifndef AP_SEQUENCE_HXX
18 #include <AP_sequence.hxx>
19 #endif
20 #ifndef _GLIBCXX_STRING
21 #include <string>
22 #endif
23 
24 struct TimedCombines {
25  clock_t ticks;
26  long combines;
27 
29  : ticks(clock()),
30  combines(AP_combinableSeq::combine_count())
31  {}
32 };
33 
35  std::string what;
36  TimedCombines start;
37  Mutations start_pars;
38 
39 public:
40  OptiPerfMeter(std::string what_, Mutations start_pars_)
41  : what(what_),
42  start_pars(start_pars_)
43  {}
44 
45  void dumpCustom(FILE *out, Mutations end_pars, const char *label) const {
46  TimedCombines end;
47 
48  ap_assert(end_pars<=start_pars);
49 
50  double seconds = double(end.ticks-start.ticks)/CLOCKS_PER_SEC;
51  double pars_improve = start_pars-end_pars;
52  long combines = end.combines-start.combines;
53 
54  double combines_per_second = combines/seconds;
55  double combines_per_improve = combines/pars_improve;
56  double improve_per_second = pars_improve/seconds;
57 
58  fprintf(out, "%-27s took %7.2f sec, improve=%9.1f, combines=%12li (comb/sec=%10.2f, comb/impr=%12.2f, impr/sec=%10.2f)\n",
59  label,
60  seconds,
61  pars_improve,
62  combines,
63  combines_per_second,
64  combines_per_improve,
65  improve_per_second);
66  }
67 
68  void dump(FILE *out, Mutations end_pars) const {
69  dumpCustom(out, end_pars, what.c_str());
70  }
71 };
72 
74  std::string what;
75  TimedCombines start;
76  int inserts;
77 
78 public:
79  InsertPerfMeter(std::string what_, int inserts_)
80  : what(what_),
81  inserts(inserts_)
82  {}
83 
84  void dumpCustom(FILE *out, const char *label) const {
85  TimedCombines end;
86 
87  double seconds = double(end.ticks-start.ticks)/CLOCKS_PER_SEC;
88  long combines = end.combines-start.combines;
89 
90  double combines_per_second = combines/seconds;
91  double combines_per_insert = combines/double(inserts);
92  double inserts_per_second = inserts/seconds;
93 
94  fprintf(out, "%-27s took %7.2f sec, inserts=%6i, combines=%12li (comb/sec=%10.2f, comb/ins=%12.2f, ins/sec=%10.2f)\n",
95  label,
96  seconds,
97  inserts,
98  combines,
99  combines_per_second,
100  combines_per_insert,
101  inserts_per_second);
102  }
103 
104  void dump(FILE *out) const {
105  dumpCustom(out, what.c_str());
106  }
107 };
108 
109 #else
110 #error PerfMeter.h included twice
111 #endif // PERFMETER_H
void dump(FILE *out, Mutations end_pars) const
Definition: PerfMeter.h:68
return string(buffer, length)
void dumpCustom(FILE *out, Mutations end_pars, const char *label) const
Definition: PerfMeter.h:45
clock_t ticks
Definition: PerfMeter.h:25
void dump(FILE *out) const
Definition: PerfMeter.h:104
OptiPerfMeter(std::string what_, Mutations start_pars_)
Definition: PerfMeter.h:40
InsertPerfMeter(std::string what_, int inserts_)
Definition: PerfMeter.h:79
long Mutations
Definition: AP_sequence.hxx:99
#define ap_assert(cond)
long combines
Definition: PerfMeter.h:26
void dumpCustom(FILE *out, const char *label) const
Definition: PerfMeter.h:84
const char * label