1 | #include <algorithm> |
---|
2 | #include <fstream> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <utility> |
---|
5 | #include "bench.hpp" |
---|
6 | #include "cpp-stack.hpp" |
---|
7 | #include "cpp-print.hpp" |
---|
8 | |
---|
9 | int main(int argc, char** argv) { |
---|
10 | std::ofstream out{"cpp-out.txt"}; |
---|
11 | srand(20171025); |
---|
12 | |
---|
13 | stack<int> s; |
---|
14 | REPEAT_TIMED( "push_int", |
---|
15 | s.push( rand() ); |
---|
16 | ) |
---|
17 | |
---|
18 | stack<int> t; |
---|
19 | TIMED( "copy_int", |
---|
20 | t = s; |
---|
21 | ) |
---|
22 | |
---|
23 | TIMED( "clear_int", |
---|
24 | s.clear(); |
---|
25 | ) |
---|
26 | |
---|
27 | int max = 0; |
---|
28 | REPEAT_TIMED( "pop_int", |
---|
29 | max = std::max( max, t.pop() ); |
---|
30 | ) |
---|
31 | print( out, max, "\n" ); |
---|
32 | |
---|
33 | REPEAT_N_TIMED( "print_int", N/2, |
---|
34 | print( out, rand(), ":", rand(), "\n" ); |
---|
35 | ) |
---|
36 | |
---|
37 | stack<std::pair<bool, char>> s2; |
---|
38 | REPEAT_TIMED( "push_bool_char", |
---|
39 | s2.push( std::pair<bool, char>{ rand() & 0x1, rand() & 0x7F } ); |
---|
40 | ) |
---|
41 | |
---|
42 | stack<std::pair<bool,char>> t2; |
---|
43 | TIMED( "copy_bool_char", |
---|
44 | t2 = s2; |
---|
45 | ) |
---|
46 | |
---|
47 | TIMED( "clear_bool_char", |
---|
48 | s2.clear(); |
---|
49 | ) |
---|
50 | |
---|
51 | std::pair<bool, char> max2 = { false, '\0' }; |
---|
52 | REPEAT_TIMED( "pop_bool_char", |
---|
53 | max2 = std::max( max2, t2.pop() ); |
---|
54 | ) |
---|
55 | print( out, max2, "\n" ); |
---|
56 | |
---|
57 | REPEAT_N_TIMED( "print_pair", N/2, |
---|
58 | print( out, std::pair<bool, char>{ rand() & 0x1, rand() & 0x7F }, ":", |
---|
59 | std::pair<bool, char>{ rand() & 0x1, rand() & 0x7F }, "\n" ); |
---|
60 | ) |
---|
61 | } |
---|