-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_benchmark.cpp
More file actions
58 lines (50 loc) · 1.54 KB
/
main_benchmark.cpp
File metadata and controls
58 lines (50 loc) · 1.54 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
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
#include <chrono>
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: %s <n> <density>\n", argv[0]);
printf(" 1 <= n <= %d\n", N_MAX);
printf(" 0 <= density <= 100\n");
return -1;
}
int n = atoi(argv[1]);
int dens = atoi(argv[2]);
printf("n = %d density = %d%%\n", n, dens);
printf("bitslice alg needs RAM: %.2lf GiB\n", (double)pow3(n)*1.0 / 8 / 1e9);
assert(1 <= n && n <= N_MAX);
assert(0 <= dens <= 100);
QuineMcCluskey D(n);
D.reserve(1ull << (n-1));
chrono::steady_clock::time_point begin = chrono::steady_clock::now();
size_t cnt = 0;
uint64_t h = -1ull;
for (uint64_t x = 0; x < (1ull << n); x++) {
h ^= (~h) >> 19; h ^= h << 17;
if (rand() % 100 < dens) {
D.set(x);
h += x;
cnt++;
}
}
printf("checksum: %016lx\n", h);
printf("inp size: %lu\n", cnt);
printf("start n = %d\n", n);
fflush(stdout);
D.run();
cnt = 0;
h = -1ull;
D.iter([&](HS_WORD xter) {
cnt++;
h ^= (~h) >> 19;
h ^= h << 17;
h += xter;
});
chrono::steady_clock::time_point end = chrono::steady_clock::now();
printf("checksum: %016lx\n", h);
printf("out size: %lu\n", cnt);
uint64_t RAM_bytes = D.get_RAM_usage();
printf("elapsed RAM: %.2f GiB = %lu bytes\n", RAM_bytes / (double)(1ull << 30), RAM_bytes);
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds> (end - begin).count();
auto seconds = std::chrono::duration_cast<std::chrono::seconds> (end - begin).count();
printf("elapsed TIME: %.3f hours = %lu nanoseconds\n", (uint64_t)seconds/3600.0, (uint64_t(ns)));
return 0;
}