-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogistic_map_test.hpp
More file actions
32 lines (25 loc) · 1.08 KB
/
logistic_map_test.hpp
File metadata and controls
32 lines (25 loc) · 1.08 KB
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
29
30
31
32
#include <random>
#include "timing.hpp"
constexpr double logisticMap(const double x) {
return 3.56999 * x * (1 - x); // this should produce very chaotic trajectories
}
double logisticMapTest(const long long loops)
{
// This function loops over the logistic map in a way that is not
// easily optimizable to test CPU performance.
// Returns elapsed seconds as double.
// This is more reliable than the sine test, because it does not rely on the cmath-implementation
auto distribution = std::uniform_real_distribution<double>(0.01, 0.99);
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 (long long i = 0; i<loops; ++i)
x = logisticMap(x);
timer.end();
return timer.elapsedTime();
}