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.cpp
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#include "etiss/Benchmark.h"
44
45namespace etiss
46{
47
48namespace benchmark
49{
50
51double averageTime(const std::list<std::pair<double, double>> &vals)
52{
53
54 if (vals.empty())
55 return NAN;
56
57 std::vector<std::pair<double, unsigned>> *vec1 = new std::vector<std::pair<double, unsigned>>();
58 std::vector<std::pair<double, unsigned>> *vec2 = new std::vector<std::pair<double, unsigned>>();
59 vec1->reserve(vals.size() / 4 + 1);
60 vec2->reserve(vals.size() / 4 + 1);
61
62 unsigned count = 0;
63 double sum = 0;
64 for (auto iter = vals.begin(); iter != vals.end(); iter++)
65 { // first sum
66 if (count == 16)
67 {
68 vec1->push_back(std::make_pair(sum, count));
69 count = 0;
70 sum = 0;
71 }
72 sum = sum + (iter->second - iter->first);
73 count++;
74 }
75 if (count > 0) // store final incomplete sum
76 vec1->push_back(std::make_pair(sum, count));
77
78 while (vec1->size() > 1)
79 {
80 sum = 0;
81 count = 0;
82 unsigned steps = 0;
83 size_t iter = 0;
84 while (iter < vec1->size())
85 {
86 if (steps == 16)
87 {
88 vec2->push_back(std::make_pair(sum, count));
89 count = 0;
90 sum = 0;
91 steps = 0;
92 }
93 auto p = (*vec1)[iter++];
94 sum += p.first;
95 count += p.second;
96 steps++;
97 }
98 if (count > 0) // store final incomplete sum
99 vec2->push_back(std::make_pair(sum, count));
100 std::swap(vec1, vec2);
101 vec2->clear();
102 }
103#if DEBUG
104 if (vec1->empty())
105 throw "error";
106#endif
107
108 return vec1->front().first / vec1->front().second;
109}
110
111} // namespace benchmark
112
113} // namespace etiss
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 NAN
A constant expression of type float representing a quiet NaN.