Ignore:
Timestamp:
Apr 14, 2017, 6:24:35 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
17f27d40, 1c38f5b, 6eb4398
Parents:
4570131
Message:

Some compaction of benchmark code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/evaluation/cpp-vbench.cpp

    r4570131 r79b8dc3  
    11#include <algorithm>
    22#include <fstream>
    3 #include <stdlib.h>
    43#include "bench.hpp"
    54#include "cpp-vstack.hpp"
     
    98int main(int argc, char** argv) {
    109        std::ofstream out{"cpp-vout.txt"};
    11         srand(20171025);
     10        stack s, t;
     11        integer max{ 0 };
     12        REPEAT_TIMED( "push_int", s.push( make<integer>( _i ) ); )
     13        TIMED( "copy_int", t = s; )
     14        TIMED( "clear_int", s.clear(); )
     15        REPEAT_TIMED( "pop_int", max = std::max( max, t.pop()->as<integer>() ); /***/ )
     16        print( out, max, c_string{"\n"} );
     17        REPEAT_N_TIMED( "print_int", N/2,
     18                print( out, integer{_i}, c_string{":"}, integer{_i}, c_string{"\n"} ); )
    1219
    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') );
     20        stack s1, t1;
     21        ptr<pair> max1 = make<pair>( make<boolean>(false), make<character>('\0') );
     22        REPEAT_TIMED( "push_bool_char",
     23                s1.push( make<pair>( make<boolean>(_i & 1), make<character>(_i & 0x7F) ) ); )
     24        TIMED( "copy_bool_char", t1 = s1; )
     25        TIMED( "clear_bool_char", s1.clear(); )
    5426        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 
     27                ptr<pair> x = as_ptr<pair>( t1.pop() ); /***/
     28                if ( *x > *max1 ) { max1 = std::move(x); } )
     29        print( out, *max1, c_string{"\n"} );
    6030        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         )
     31                print( out, pair{ make<boolean>(_i & 1), make<character>(_i & 0x7F) }, c_string{":"},
     32                        pair{ make<boolean>(_i & 1), make<character>(_i & 0x7F) }, c_string{"\n"} ); )
    6633}
Note: See TracChangeset for help on using the changeset viewer.