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 | srand(20171025); |
---|
11 | |
---|
12 | stack s; |
---|
13 | REPEAT_TIMED( "push_int", |
---|
14 | s.push( std::make_unique<integer>( rand() ) ); |
---|
15 | ) |
---|
16 | |
---|
17 | stack t; |
---|
18 | TIMED( "copy_int", |
---|
19 | t = s; |
---|
20 | ) |
---|
21 | |
---|
22 | TIMED( "clear_int", |
---|
23 | s.clear(); |
---|
24 | ) |
---|
25 | |
---|
26 | integer max; |
---|
27 | REPEAT_TIMED( "pop_int", |
---|
28 | max = std::max( max, t.pop()->as<integer>() ); |
---|
29 | ) |
---|
30 | |
---|
31 | stack s2; |
---|
32 | REPEAT_TIMED( "push_bool_char", |
---|
33 | s2.push( std::make_unique<pair>( std::make_unique<boolean>( rand() & 0x1 ), |
---|
34 | std::make_unique<character>( rand() & 0x7F ) ) ); |
---|
35 | ) |
---|
36 | |
---|
37 | stack t2; |
---|
38 | TIMED( "copy_bool_char", |
---|
39 | t2 = s2; |
---|
40 | ) |
---|
41 | |
---|
42 | TIMED( "clear_bool_char", |
---|
43 | s2.clear(); |
---|
44 | ) |
---|
45 | |
---|
46 | auto max2 = std::make_unique<pair>( std::make_unique<boolean>(false), |
---|
47 | std::make_unique<character>('\0') ); |
---|
48 | REPEAT_TIMED( "pop_bool_char", |
---|
49 | std::unique_ptr<pair> x = as_ptr<pair>( t2.pop() ); |
---|
50 | if ( *x > *max2 ) { max2 = std::move(x); } |
---|
51 | ) |
---|
52 | |
---|
53 | std::ofstream out{"cpp-vout.txt"}; |
---|
54 | REPEAT_TIMED( "print_int", |
---|
55 | print( out, integer{rand()}, c_string{":"}, integer{rand()}, c_string{"\n"} ); |
---|
56 | ) |
---|
57 | |
---|
58 | REPEAT_TIMED( "print_pair", |
---|
59 | print( out, pair{ std::make_unique<boolean>( rand() & 0x1 ), |
---|
60 | std::make_unique<character>( rand() & 0x7F ) }, c_string{":"}, |
---|
61 | pair{ std::make_unique<boolean>( rand() & 0x1 ), |
---|
62 | std::make_unique<character>( rand() & 0x7F ) }, c_string{"\n"} ); |
---|
63 | ) |
---|
64 | } |
---|