-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsin_test.hpp
More file actions
28 lines (22 loc) · 878 Bytes
/
sin_test.hpp
File metadata and controls
28 lines (22 loc) · 878 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 <random>
#include "timing.hpp"
double sinusTest(const size_t loops)
{
// This function loops over the sinus function in a way that is not
// easily optimizable to test CPU performance.
// Returns elapsed seconds as double.
auto distribution = std::uniform_real_distribution<double>(0, M_PI);
auto generator = std::default_random_engine(timing::secondsSinceEpoch());
auto rand = std::bind(distribution, generator);
// draw a random number based on external parameters to avoid compile-time execution.
// We use volatile here to ensure that the benchmark is actually compiled
// into the program and performed.
volatile double x = rand();
timing::Measurement timer;
timer.start();
for (size_t i = 0; i<loops; ++i)
x = std::sin(3*x);
timer.end();
return timer.elapsedTime();
}