ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Benchmark.h
Go to the documentation of this file.
1/*
2
3 @copyright
4
5 <pre>
6
7 Copyright 2018 Infineon Technologies AG
8
9 This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10
11 The initial version of this software has been created with the funding support by the German Federal
12 Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13
14 Redistribution and use in source and binary forms, with or without modification, are permitted
15 provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18 the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21 and the following disclaimer in the documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24 or promote products derived from this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34
35 </pre>
36
37 @author Chair of Electronic Design Automation, TUM
38
39 @version 0.1
40
41*/
42
43#ifndef ETISS_BENCHMARK_H
44#define ETISS_BENCHMARK_H
45
46#include "etiss/Misc.h"
47
48#include <cmath>
49#include <ctime>
50#include <list>
51
52namespace etiss
53{
54
56{
57 double operator()() { return (clock() / (double)CLOCKS_PER_SEC) * 1000000000.0; }
58};
59
60namespace benchmark
61{
62double averageTime(const std::list<std::pair<double, double>> &vals);
63}
64
65template <typename clock_ = Default_Clock>
67{
68 public:
69 clock_ clock_inst;
70 const std::string name_;
71 Benchmark(const std::string &name) : name_(name), state(false) {}
72 void start()
73 {
74#if DEBUG
75 if (unlikely(state != false))
76 throw "benchmark not stopped before calling start";
77#endif
78 state = true;
79 cur.first = clock_inst();
80 }
81 void stop(size_t interval_count = 1)
82 {
83#if DEBUG
84 if (unlikely(state != true))
85 throw "benchmark not started before calling start";
86#endif
87 state = false;
88 cur.second = clock_inst();
89 interval_ns.push_back(cur);
90 }
91 std::list<std::pair<double, double>> interval_ns;
92 std::string toString() const
93 {
94 std::stringstream ss;
95 ss << name_ << " { average=" << etiss::benchmark::averageTime(interval_ns)
96 << "ns samples=" << interval_ns.size() << "}";
97 return ss.str();
98 }
99
100 private:
101 std::pair<double, double> cur;
102 bool state;
103
104 public:
105};
106
107} // namespace etiss
108
109#endif // ETISS_BENCHMARK_H
general configuration and logging
__DEVICE__ int clock()
#define unlikely(x)
Definition types.h:74
void stop(size_t interval_count=1)
Definition Benchmark.h:81
Benchmark(const std::string &name)
Definition Benchmark.h:71
const std::string name_
Definition Benchmark.h:70
clock_ clock_inst
Definition Benchmark.h:69
std::list< std::pair< double, double > > interval_ns
Definition Benchmark.h:91
std::pair< double, double > cur
Definition Benchmark.h:101
std::string toString() const
Definition Benchmark.h:92
Marker interface for toString() support.
Definition Misc.h:137
double averageTime(const std::list< std::pair< double, double > > &vals)
Definition Benchmark.cpp:51
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition Benchmark.h:53
#define false
Definition stdbool.h:17