-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cc
111 lines (87 loc) · 3.2 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "board.h"
#include "board_optimized.h"
#include <chrono>
#include <opencv2/highgui.hpp>
#include <unistd.h>
int main() {
Board::GodFunction god_fn_0 = [](unsigned int neighbors,
State current_state) {
if (current_state == LIVE) {
if (neighbors == 2 || neighbors == 3)
return LIVE;
return DEAD; // greater than 3 die
} else if (neighbors == 3) // dead but has exactly 3 neighbors live
return LIVE;
return DEAD;
};
/*
***************************** Step 1 ********************************
*/
std::cout << "Iteration beginning, count: 100, board size 256x256\n";
auto board_256 = Board(256);
auto begin = std::chrono::steady_clock::now();
for (unsigned int i{0}; i < 100; ++i) {
board_256.run(god_fn_0);
}
auto end = std::chrono::steady_clock::now();
std::cout << "Elapsed: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end -
begin)
.count()
<< " [ms]"
<< "\n";
auto board_optimized_256 = BoardOptimized<256>();
begin = std::chrono::steady_clock::now();
for (unsigned int i{0}; i < 100; ++i) {
board_optimized_256.run();
// board_optimized_256.print();
}
end = std::chrono::steady_clock::now();
// board_optimized_256.destroyWindow();
std::cout << "[OPTIMIZED] Elapsed: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end -
begin)
.count()
<< " [ms]"
<< "\n";
// board_optimized_256.destroyWindow();
if (board_256.match(
[&](int i, int j) { return board_optimized_256.get_at(i, j); }))
std::cout << "States matched!\n";
else
std::cout << "States did not match!\n";
/*
***************************** Step 2 ********************************
*/
std::cout << "Iteration beginning, count: 1000, board size 2048x2048\n";
// auto board_2048 = Board(2048);
// begin = std::chrono::steady_clock::now();
// for (unsigned int i{0}; i < 1000; ++i) {
// board_2048.run(god_fn_0);
// }
// end = std::chrono::steady_clock::now();
// std::cout << "Elapsed: "
// << std::chrono::duration_cast<std::chrono::milliseconds>(end -
// begin)
// .count()
// << " [ms]"
// << "\n";
auto board_optimized_2048 = BoardOptimized<2048>();
begin = std::chrono::steady_clock::now();
for (unsigned int i{0}; i < 1000; ++i) {
board_optimized_2048.run();
}
end = std::chrono::steady_clock::now();
std::cout << "[OPTIMIZED] Elapsed: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end -
begin)
.count()
<< " [ms]"
<< "\n";
// if (board_2048.match(
// [&](int i, int j) { return board_optimized_2048.get_at(i, j); }))
// std::cout << "States matched!\n";
// else
// std::cout << "States did not match!\n";
return 0;
}