summaryrefslogtreecommitdiff
path: root/test/math/piLehmer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/math/piLehmer.cpp')
-rw-r--r--test/math/piLehmer.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/math/piLehmer.cpp b/test/math/piLehmer.cpp
new file mode 100644
index 0000000..d84466f
--- /dev/null
+++ b/test/math/piLehmer.cpp
@@ -0,0 +1,42 @@
+#include "../util.h"
+#include <math/primeSieve.cpp>
+namespace legendre {
+ #include <math/piLegendre.cpp>
+}
+namespace lehmer {
+ #include <math/piLehmer.cpp>
+}
+
+void stress_test() {
+ int queries = 0;
+ for (int i = 0; i < 1'000; i++) {
+ ll x = Random::integer<ll>(0, 1'000'000'000);
+ auto got = lehmer::pi(x);
+ auto expected = legendre::pi(x);
+ if (got != expected) cerr << "got: " << got << ", expected: " << expected << FAIL;
+ queries++;
+ }
+ cerr << "tested random queries: " << queries << endl;
+}
+
+void performance_test() {
+ timer t;
+ hash_t hash = 0;
+ t.start();
+ lehmer::init();
+ t.stop();
+ for (int i = 0; i < 1; i++) {
+ ll x = Random::integer<ll>(0, 1000'000'000'000);
+ t.start();
+ hash += lehmer::pi(x);
+ t.stop();
+ }
+ if (t.time > 1500) cerr << "too slow: " << t.time << FAIL;
+ cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl;
+}
+
+int main() {
+ performance_test();
+ stress_test();
+}
+