ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Benchmark.cpp
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#include "etiss/Benchmark.h"
8
9namespace etiss
10{
11
12namespace benchmark
13{
14
15double averageTime(const std::list<std::pair<double, double>> &vals)
16{
17
18 if (vals.empty())
19 return NAN;
20
21 std::vector<std::pair<double, unsigned>> *vec1 = new std::vector<std::pair<double, unsigned>>();
22 std::vector<std::pair<double, unsigned>> *vec2 = new std::vector<std::pair<double, unsigned>>();
23 vec1->reserve(vals.size() / 4 + 1);
24 vec2->reserve(vals.size() / 4 + 1);
25
26 unsigned count = 0;
27 double sum = 0;
28 for (auto iter = vals.begin(); iter != vals.end(); iter++)
29 { // first sum
30 if (count == 16)
31 {
32 vec1->push_back(std::make_pair(sum, count));
33 count = 0;
34 sum = 0;
35 }
36 sum = sum + (iter->second - iter->first);
37 count++;
38 }
39 if (count > 0) // store final incomplete sum
40 vec1->push_back(std::make_pair(sum, count));
41
42 while (vec1->size() > 1)
43 {
44 sum = 0;
45 count = 0;
46 unsigned steps = 0;
47 size_t iter = 0;
48 while (iter < vec1->size())
49 {
50 if (steps == 16)
51 {
52 vec2->push_back(std::make_pair(sum, count));
53 count = 0;
54 sum = 0;
55 steps = 0;
56 }
57 auto p = (*vec1)[iter++];
58 sum += p.first;
59 count += p.second;
60 steps++;
61 }
62 if (count > 0) // store final incomplete sum
63 vec2->push_back(std::make_pair(sum, count));
64 std::swap(vec1, vec2);
65 vec2->clear();
66 }
67#if DEBUG
68 if (vec1->empty())
69 throw "error";
70#endif
71
72 return vec1->front().first / vec1->front().second;
73}
74
75} // namespace benchmark
76
77} // namespace etiss
double averageTime(const std::list< std::pair< double, double > > &vals)
Definition Benchmark.cpp:15
forwards: include/jit/*
Definition Benchmark.h:17
#define NAN
A constant expression of type float representing a quiet NaN.