-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
73 lines (54 loc) · 1.73 KB
/
main.cc
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
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <chrono>
#include <cstdlib>
#include <stdlib.h>
#include "tools/Random.h"
#include "tools/MatchBin.h"
#include "tools/matchbin_utils.h"
int main(int argc, char *argv[]) {
// initialize MatchBin
size_t iterations;
size_t seed;
if (argc != 3) {
// defaults
iterations = 1000;
seed = 2;
} else {
iterations = std::atoi(argv[1]);
seed = std::atoi(argv[2]);
}
emp::Random random(seed);
emp::MatchBin<
int,
emp::NextUpMetric<>,
emp::RankedSelector<>,
emp::NopRegulator
> bin(random);
// seed rand()
std::srand(seed);
// put elements into MatchBin
std::cout << "Putting elements into MatchBin..." << std::endl;
for (size_t tag = 0; tag < iterations; tag++) {
int value = std::rand();
bin.Put(value, tag);
}
/* ------ BENCHMARK! ------ */
size_t result = 0;
std::cout << "Benchmarking..." << std::endl;
// start hig-res timer
auto start_time = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < iterations; i++) {
// get values
emp::vector<int> matches = bin.GetVals(bin.Match(i));
// do something with result, so that it is not optimized away
result += matches.size();
}
// end timer
auto end_time = std::chrono::high_resolution_clock::now();
std::cout << "Results!\n" << std::endl;
// print final result, just in case the compiler feels like optimizing it away
std::cout << "result: " << result << std::endl;
// calculate and print timing
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count();
std::cout << duration << std::endl;
}