-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add simple Stats class for statistics * Add error bars based on SEM to plots where mean is reported * Add a warmup run * Run 20 steps/iterations * Improve plot display (bar borders, xtic nomirror) Fixes: #401
- Loading branch information
1 parent
07ae18d
commit d81094c
Showing
10 changed files
with
275 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2023 Bernhard Manfred Gruber | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include <cmath> | ||
#include <numeric> | ||
#include <vector> | ||
|
||
namespace common | ||
{ | ||
struct Stats | ||
{ | ||
bool skipNext = true; // to ignore 1 warmup run | ||
std::vector<double> values; | ||
|
||
Stats() | ||
{ | ||
// make sure benchmarks don't incur a reallocation | ||
values.reserve(100); | ||
} | ||
|
||
void operator()(double val) | ||
{ | ||
if(skipNext) | ||
skipNext = false; | ||
else | ||
values.push_back(val); | ||
} | ||
|
||
auto sum() const -> double | ||
{ | ||
return std::reduce(values.begin(), values.end()); | ||
} | ||
|
||
auto mean() const -> double | ||
{ | ||
return sum() / static_cast<double>(values.size()); | ||
} | ||
|
||
// sample standard deviation | ||
auto sstddev() const -> double | ||
{ | ||
double sum = 0; | ||
const auto m = mean(); | ||
for(auto v : values) | ||
sum += (v - m) * (v - m); | ||
return std::sqrt(sum / static_cast<double>(values.size() - 1)); | ||
} | ||
|
||
auto sem() const -> double | ||
{ | ||
return sstddev() / std::sqrt(values.size()); | ||
} | ||
|
||
auto operator+=(const Stats& s) -> Stats& | ||
{ | ||
values.insert(values.end(), s.values.begin(), s.values.end()); | ||
return *this; | ||
} | ||
|
||
friend auto operator+(Stats a, const Stats& b) -> Stats | ||
{ | ||
return a += b; | ||
} | ||
}; | ||
} // namespace common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.