[87c5f40] | 1 | #include <algorithm> |
---|
[0d10090] | 2 | #include <fstream> |
---|
[b276be5] | 3 | #include <stdlib.h> |
---|
| 4 | #include "bench.hpp" |
---|
| 5 | #include "cpp-vstack.hpp" |
---|
[0d10090] | 6 | #include "cpp-vprint.hpp" |
---|
[87c5f40] | 7 | #include "object.hpp" |
---|
[b276be5] | 8 | |
---|
| 9 | int main(int argc, char** argv) { |
---|
[3fb7f5e] | 10 | std::ofstream out{"cpp-vout.txt"}; |
---|
[b276be5] | 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 | |
---|
[87c5f40] | 27 | integer max; |
---|
[b276be5] | 28 | REPEAT_TIMED( "pop_int", |
---|
[3fb7f5e] | 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"} ); |
---|
[87c5f40] | 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 | |
---|
[b14dd03] | 52 | auto max2 = std::make_unique<pair>( std::make_unique<boolean>(false), |
---|
| 53 | std::make_unique<character>('\0') ); |
---|
[87c5f40] | 54 | REPEAT_TIMED( "pop_bool_char", |
---|
[3fb7f5e] | 55 | std::unique_ptr<pair> x = as_ptr<pair>( t2.pop() ); /***/ |
---|
[0d10090] | 56 | if ( *x > *max2 ) { max2 = std::move(x); } |
---|
| 57 | ) |
---|
[3fb7f5e] | 58 | print( out, *max2, c_string{"\n"} ); |
---|
[0d10090] | 59 | |
---|
[3fb7f5e] | 60 | REPEAT_N_TIMED( "print_pair", N/2, |
---|
[0d10090] | 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"} ); |
---|
[b276be5] | 65 | ) |
---|
| 66 | } |
---|