ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Benchmark.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
7#ifndef ETISS_BENCHMARK_H
8#define ETISS_BENCHMARK_H
9
10#include "etiss/Misc.h"
11
12#include <cmath>
13#include <ctime>
14#include <list>
15
16namespace etiss
17{
18
20{
21 double operator()() { return (clock() / (double)CLOCKS_PER_SEC) * 1000000000.0; }
22};
23
24namespace benchmark
25{
26double averageTime(const std::list<std::pair<double, double>> &vals);
27}
28
29template <typename clock_ = Default_Clock>
31{
32 public:
33 clock_ clock_inst;
34 const std::string name_;
35 Benchmark(const std::string &name) : name_(name), state(false) {}
36 void start()
37 {
38#if DEBUG
39 if (unlikely(state != false))
40 throw "benchmark not stopped before calling start";
41#endif
42 state = true;
43 cur.first = clock_inst();
44 }
45 void stop(size_t interval_count = 1)
46 {
47#if DEBUG
48 if (unlikely(state != true))
49 throw "benchmark not started before calling start";
50#endif
51 state = false;
52 cur.second = clock_inst();
53 interval_ns.push_back(cur);
54 }
55 std::list<std::pair<double, double>> interval_ns;
56 std::string toString() const
57 {
58 std::stringstream ss;
59 ss << name_ << " { average=" << etiss::benchmark::averageTime(interval_ns)
60 << "ns samples=" << interval_ns.size() << "}";
61 return ss.str();
62 }
63
64 private:
65 std::pair<double, double> cur;
66 bool state;
67
68 public:
69};
70
71} // namespace etiss
72
73#endif // ETISS_BENCHMARK_H
general configuration and logging
__DEVICE__ int clock()
#define unlikely(x)
Definition types.h:36
void stop(size_t interval_count=1)
Definition Benchmark.h:45
Benchmark(const std::string &name)
Definition Benchmark.h:35
const std::string name_
Definition Benchmark.h:34
clock_ clock_inst
Definition Benchmark.h:33
std::list< std::pair< double, double > > interval_ns
Definition Benchmark.h:55
std::pair< double, double > cur
Definition Benchmark.h:65
std::string toString() const
Definition Benchmark.h:56
Marker interface for toString() support.
Definition Misc.h:95
double averageTime(const std::list< std::pair< double, double > > &vals)
Definition Benchmark.cpp:15
forwards: include/jit/*
Definition Benchmark.h:17
#define false
Definition stdbool.h:17