source: branches/profile/PARSIMONY/PerfMeter.h

Last change on this file was 13642, checked in by westram, 9 years ago
  • add perfmeter (insert + optimize)
  • disable AUTO_CHECK_TREE_STRUCTURE (4me)
File size: 3.2 KB
Line 
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
24struct TimedCombines {
25    clock_t ticks;
26    long    combines;
27
28    TimedCombines()
29        : ticks(clock()),
30          combines(AP_sequence::combine_count())
31    {}
32};
33
34class OptiPerfMeter {
35    std::string   what;
36    TimedCombines start;
37    AP_FLOAT      start_pars;
38
39public:
40    OptiPerfMeter(std::string what_, AP_FLOAT start_pars_)
41        : what(what_),
42          start_pars(start_pars_)
43    {}
44
45    void dumpCustom(FILE *out, AP_FLOAT 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        AP_FLOAT 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, AP_FLOAT end_pars) const {
69        dumpCustom(out, end_pars, what.c_str());
70    }
71};
72
73class InsertPerfMeter {
74    std::string   what;
75    TimedCombines start;
76    int           inserts;
77
78public:
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
Note: See TracBrowser for help on using the repository browser.