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