Ignore:
Timestamp:
Apr 14, 2017, 6:24:35 PM (8 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-bench.cpp

    r4570131 r79b8dc3  
    11#include <algorithm>
    22#include <fstream>
    3 #include <stdlib.h>
    43#include <utility>
    54#include "bench.hpp"
     
    98int main(int argc, char** argv) {
    109        std::ofstream out{"cpp-out.txt"};
    11         srand(20171025);
     10        stack<int> s, t;
     11        int max = 0;
     12        REPEAT_TIMED( "push_int", s.push( _i ); )
     13        TIMED( "copy_int", t = s; )
     14        TIMED( "clear_int", s.clear(); )
     15        REPEAT_TIMED( "pop_int", max = std::max( max, t.pop() ); )
     16        print( out, max, "\n" );
     17        REPEAT_N_TIMED( "print_int", N/2, print( out, _i, ":", _i, "\n" ); )
    1218
    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 
     19        stack<std::pair<bool, char>> s1, t1;
     20        std::pair<bool, char> max1 = { false, '\0' };
     21        REPEAT_TIMED( "push_bool_char", s1.push( std::pair<bool, char>{ _i & 0x1, _i & 0x7F } ); )
     22        TIMED( "copy_bool_char", t1 = s1; )
     23        TIMED( "clear_bool_char", s1.clear(); )
     24        REPEAT_TIMED( "pop_bool_char", max1 = std::max( max1, t1.pop() ); )
     25        print( out, max1, "\n" );
    5726        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         )
     27                print( out, std::pair<bool, char>{ _i & 0x1, _i & 0x7F }, ":",
     28                                std::pair<bool, char>{ _i & 0x1, _i & 0x7F }, "\n" ); )
    6129}
Note: See TracChangeset for help on using the changeset viewer.