-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.cpp
62 lines (57 loc) · 1.6 KB
/
log.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Created by mbarbone on 12/1/21.
//
#include "logarithms.h"
#include "utils.h"
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
#include <random>
using real_type = float;
std::vector<real_type> inputs;
std::vector<double> reference;
std::vector<float> result;
TEST_CASE("Logarithm") {
reference.resize(TESTS);
BENCHMARK("STD DOUBLE") {
for (int i = 0; i < TESTS; ++i) {
reference[i] = std::log(static_cast<double>(inputs[i]));
}
};
result.resize(TESTS);
BENCHMARK("STD SINGLE") {
for (int i = 0; i < TESTS; ++i) {
result[i] = std::log(inputs[i]);
}
};
checkError(reference, result);
BENCHMARK("FAST LOGF") {
for (int i = 0; i < TESTS; ++i) {
result[i] = fast_logf(inputs[i]);
}
};
checkError(reference, result);
BENCHMARK("APPROXIMATE LOGF") {
for (int i = 0; i < TESTS; ++i) {
result[i] = approximate_logf(inputs[i]);
}
};
checkError(reference, result);
BENCHMARK("FASTER LOGF") {
for (int i = 0; i < TESTS; ++i) {
result[i] = faster_logf(inputs[i]);
}
};
checkError(reference, result);
}
int main(int argc, char *argv[]) {
auto seed = std::random_device()();
std::cout << "Seed " << seed << std::endl;
std::default_random_engine rng{seed};
std::uniform_real_distribution<real_type> distribution{0, 1};
inputs.resize(TESTS);
for (int i = 0; i < TESTS; ++i) {
inputs[i] = distribution(rng);
}
return Catch::Session().run(argc, argv);
}