File: TimerList.h

package info (click to toggle)
dds 2.9.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 56,572 kB
  • sloc: cpp: 17,621; ansic: 385; makefile: 27; xml: 11; sh: 7
file content (107 lines) | stat: -rw-r--r-- 2,423 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
   DDS, a bridge double dummy solver.

   Copyright (C) 2006-2014 by Bo Haglund /
   2014-2018 by Bo Haglund & Soren Hein.

   See LICENSE and README.
*/

/*
   TimerList consists of a number of groups, one for each piece
   of the code being timed (ABsearch etc).

   Each group corresponds to something that should be timed at
   multiple AB depths, i.e. cards played. The first card of a
   new game is number 48, and the last card is number 0.

   The AB timer is special, as the AB functions are recursive
   and so their timing includes not only the other functions they
   contain, but also their own recursive calls at lower depths.
   The AB timer group must be the first one.

   The object calculates an approximation to exclusive function
   times, so it is a "poor man's profiler".

   For AB, first the times at depth-1 are subtracted out, and then
   the times for all calls at the same depth are subtracted out.
   This still leaves the overhead of the timing itself. As an
   approximation, there is one timing overhead left for each
   function, and it is on the order of the execution time of
   Evaluate(), which is a very fast function.

   TIMER_START and TIMER_END are macros for bracketing code
   to be timed, so

   TIMER_START(TIMER_NO_AB, depth);
   ABsearch(...);
   TIMER_END(TIMER_NO_AB, depth);

   This avoids the tedious #ifdef's at every place of a timer.
 */

#ifndef DDS_TIMERLIST_H
#define DDS_TIMERLIST_H

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

#include "TimerGroup.h"
#include "debug.h"

using namespace std;


#ifdef DDS_TIMING
  #define TIMER_START(g, a) thrp->timerList.Start(g, a)
  #define TIMER_END(g, a) thrp->timerList.End(g, a)
#else
  #define TIMER_START(g, a) 1
  #define TIMER_END(g, a) 1
#endif

enum ABTimerType
{
  TIMER_NO_AB = 0,
  TIMER_NO_MAKE = 1,
  TIMER_NO_UNDO = 2,
  TIMER_NO_EVALUATE = 3,
  TIMER_NO_NEXTMOVE = 4,
  TIMER_NO_QT = 5,
  TIMER_NO_LT = 6,
  TIMER_NO_MOVEGEN = 7,
  TIMER_NO_LOOKUP = 8,
  TIMER_NO_BUILD = 9,
  TIMER_NO_SIZE = 10
};


class TimerList
{
  private:

    vector<TimerGroup> timerGroups;

  public:
    TimerList();

    ~TimerList();

    void Reset();

    void Start(
      const ABTimerType groupno,
      const unsigned timerno);

    void End(
      const ABTimerType groupno,
      const unsigned timerno);

    bool Used() const;

    void PrintStats(ofstream& fout) const;
};

#endif