forked from neumannt/exceptionperformance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseline.cpp
More file actions
28 lines (24 loc) · 802 Bytes
/
baseline.cpp
File metadata and controls
28 lines (24 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <cmath>
#include <exception>
#include <span>
static void doSqrt(std::span<double> values) noexcept {
for (auto& v : values) {
if (v < 0) std::terminate();
v = sqrt(v);
}
}
unsigned baselineSqrt(std::span<double> values, unsigned repeat) {
unsigned failures = 0;
for (unsigned index = 0; index != repeat; ++index)
doSqrt(values);
return failures;
}
static unsigned doFib(unsigned n, unsigned maxDepth) noexcept __attribute__((noinline, optimize("no-optimize-sibling-calls")));
static unsigned doFib(unsigned n, unsigned maxDepth) noexcept {
if (!maxDepth) std::terminate();
if (n <= 2) return 1;
return doFib(n - 2, maxDepth - 1) + doFib(n - 1, maxDepth - 1);
}
unsigned baselineFib(unsigned n, unsigned maxDepth) {
return doFib(n, maxDepth);
}