~tapaal-red/verifypn/rule-l

« back to all changes in this revision

Viewing changes to include/CTL/Stopwatch.h

  • Committer: Peter G. Jensen
  • Date: 2020-03-02 21:03:24 UTC
  • mto: (213.1.38 verifypn_cmake)
  • mto: This revision was merged to the branch mainline in revision 225.
  • Revision ID: peter.gjoel@gmail.com-20200302210324-mmaia5l9vthz8oxx
adding rebuild structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef STOPWATCH_H
 
2
#define STOPWATCH_H
 
3
 
 
4
#include <ctime>
 
5
#include <sstream>
 
6
 
 
7
using namespace std;
 
8
 
 
9
class stopwatch {
 
10
    bool _running = false;
 
11
    clock_t _start;
 
12
    clock_t _stop;
 
13
 
 
14
public:
 
15
    double started() const { return _start; }
 
16
    double stopped() const { return _stop; }
 
17
    bool running() const { return _running; }
 
18
    void start() {
 
19
        _running = true;
 
20
        _start = clock();
 
21
    }
 
22
    void stop() {
 
23
        _stop = clock();
 
24
        _running = false;
 
25
    }
 
26
    double duration() const { return ( (double(_stop - _start))*1000)/CLOCKS_PER_SEC; }
 
27
 
 
28
    ostream &operator<<(ostream &os){
 
29
        os << duration() << " ms";
 
30
        return os;
 
31
    }
 
32
 
 
33
    std::string toString(){
 
34
        stringstream ss;
 
35
        ss << this;
 
36
        return ss.str();
 
37
    }
 
38
};
 
39
 
 
40
#endif // STOPWATCH_H