blob: c3513bf2b727fc60d459561caac09e4e74151ab7 (
plain)
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
|
#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 = legendre::pi(x);
auto expected = lehmer::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;
for (int i = 0; i < 1; i++) {
ll x = Random::integer<ll>(0, 1000'000'000'000);
t.start();
hash += legendre::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() {
lehmer::init();
performance_test();
stress_test();
}
|