Changeset a91dcc2 for src/examples


Ignore:
Timestamp:
Jan 30, 2017, 12:57:57 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
6dc78dee, a9fc180
Parents:
059531a6
Message:

Modified benchmark to only display relevant information

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/Bench.c

    r059531a6 ra91dcc2  
    1 
    21
    32#include <fstream>
     3#include <stdlib>
    44#include <threads>
    55
     
    2525
    2626//=======================================
     27// time struct
     28//=======================================
     29
     30// prevent dead-code removal
     31struct StructDummy {
     32        volatile int i;
     33};
     34
     35void ?{}(StructDummy * this) __attribute__(( noinline )) {
     36        this->i = 2;
     37}
     38
     39int get_i(StructDummy * this) {
     40        return this->i;
     41}
     42
     43forall( dtype T | { int get_i(T*); } )
     44int bidirectional( StructDummy * this ) __attribute__(( noinline )) {
     45        return get_i( this );
     46}
     47
     48void BlockStructCreateDelete( int N ) {
     49    long long int StartTime, EndTime;
     50
     51    StartTime = Time();
     52    for ( int i = 0; i < N; i += 1 ) {
     53        StructDummy dummy;
     54    }
     55    EndTime = Time();
     56    sout | "\t " | ( EndTime - StartTime ) / N;
     57}
     58
     59void DynamicStructCreateDelete( int N ) {
     60    long long int StartTime, EndTime;
     61
     62    StartTime = Time();
     63    for ( int i = 0; i < N; i += 1 ) {
     64        StructDummy *dummy = new();
     65        delete(dummy);
     66    }
     67    EndTime = Time();
     68    sout | "\t " | ( EndTime - StartTime ) / N;
     69}
     70
     71void StructBidirectional( int N ) {
     72    long long int StartTime, EndTime;
     73    StructDummy dummy;
     74    volatile int rv __attribute__(( unused ));
     75
     76    StartTime = Time();
     77    for ( int i = 0; i < N; i += 1 ) {
     78        rv = bidirectional( &dummy );
     79    }
     80    EndTime = Time();
     81    sout | "\t " | ( EndTime - StartTime ) / N;
     82}
     83
     84//=======================================
    2785// time coroutine
    2886//=======================================
     87
     88struct CoroutineDummy { coroutine c; };
     89DECL_COROUTINE(CoroutineDummy)
     90void main(CoroutineDummy * this) {}
     91
     92void ?{}(CoroutineDummy * this) {
     93        prime(this);
     94}
     95
     96void BlockCoroutineCreateDelete( int N ) {
     97    long long int StartTime, EndTime;
     98
     99    StartTime = Time();
     100    for ( int i = 0; i < N; i += 1 ) {
     101        CoroutineDummy dummy;
     102    }
     103    EndTime = Time();
     104    sout | "\t " | ( EndTime - StartTime ) / N;
     105}
     106
     107void DynamicCoroutineCreateDelete( int N ) {
     108    long long int StartTime, EndTime;
     109
     110    StartTime = Time();
     111    for ( int i = 0; i < N; i += 1 ) {
     112        CoroutineDummy * dummy = new();
     113        delete(dummy);
     114    }
     115    EndTime = Time();
     116    sout | "\t " | ( EndTime - StartTime ) / N;
     117}
    29118
    30119struct CoroutineResume {
     
    33122};
    34123
    35 coroutine* get_coroutine(CoroutineResume* this);
    36 void co_main(CoroutineResume* this);
     124DECL_COROUTINE(CoroutineResume)
    37125
    38126void ?{}(CoroutineResume* this, int N) {
     
    41129}
    42130
    43 coroutine* get_coroutine(CoroutineResume* this) {
    44       return &this->c;
    45 }
    46 
    47 void co_main(CoroutineResume* this) {
     131void main(CoroutineResume* this) {
    48132        for ( int i = 1; i <= this->N; i += 1 ) {
    49133                suspend();
    50         } // for
    51 } // CoroutineResume::main
     134        }
     135}
    52136
    53137void resumer(CoroutineResume* this) {
     
    57141        for ( int i = 1; i <= this->N; i += 1 ) {
    58142                resume(this);
     143        }
     144        EndTime = Time();
     145        sout | "\t " | ( EndTime - StartTime ) / this->N;
     146}
     147
     148//=======================================
     149// time task
     150//=======================================
     151
     152struct ThreadDummy { thread t; };
     153DECL_THREAD(ThreadDummy)
     154void main(ThreadDummy * this) {}
     155
     156void BlockTaskCreateDelete( int N ) {
     157    long long int StartTime, EndTime;
     158
     159    StartTime = Time();
     160    for ( int i = 0; i < N; i += 1 ) {
     161        scoped(ThreadDummy) dummy;
     162    }
     163    EndTime = Time();
     164    sout | "\t " | ( EndTime - StartTime ) / N;
     165}
     166
     167void DynamicTaskCreateDelete( int N ) {
     168    long long int StartTime, EndTime;
     169
     170    StartTime = Time();
     171    for ( int i = 0; i < N; i += 1 ) {
     172        scoped(ThreadDummy) * dummy = new();
     173        delete(dummy);
     174    }
     175    EndTime = Time();
     176    sout | "\t " | ( EndTime - StartTime ) / N;
     177}
     178
     179struct ContextSwitch {
     180    int N;
     181    long long result;
     182    thread t;
     183};
     184
     185DECL_THREAD(ContextSwitch)
     186
     187void main(ContextSwitch * this) {   
     188        long long int StartTime, EndTime;
     189
     190        StartTime = Time();
     191        for ( int i = 1; i <= this->N; i += 1 ) {
     192            yield();
    59193        } // for
    60194        EndTime = Time();
    61         sout | "\t " | ( EndTime - StartTime ) / this->N;
    62 } // CoroutineResume::resumer
     195        this->result = ( EndTime - StartTime ) / this->N;
     196}
     197
     198void ?{}(ContextSwitch * this, int N) {
     199        this->N = N;
     200}
     201
     202void ^?{}(ContextSwitch * this) {
     203        sout | "\t " | this->result;
     204}
     205
     206//=======================================
     207// benchmark driver
     208//=======================================
    63209
    64210
     
    71217#endif // __U_DEBUG__
    72218
    73         sout | "\t\tcreate\tcreate\t16i/4o\t16i/4o\tresume/\tsignal/" | endl;
     219        sout | "\t\tcreate\tcreate\tcall/" | endl;
    74220        sout | "(nsecs)";
    75         sout | "\t\tdelete/\tdelete/\tbytes\tbytes\tsuspend\twait" | endl;
    76         sout | "\t\tblock\tdynamic\tdirect\taccept\tcycle\tcycle" | endl;
    77 
    78         sout | "class\t";
    79         sout | "\t N/A\t N/A\t N/A";
    80         sout | "\t N/A\t N/A\t N/A";
    81         sout | "\t" | endl;
     221        sout | "\t\tdelete/\tdelete/\tctx" | endl;
     222        sout | "\t\tblock\tdynamic\tcycle" | endl;
     223
     224        sout | "object\t";
     225        BlockStructCreateDelete( NoOfTimes );
     226        DynamicStructCreateDelete( NoOfTimes );
     227        StructBidirectional( NoOfTimes );
     228        sout | endl;
    82229
    83230        sout | "coroutine";
    84         sout | "\t N/A\t N/A\t N/A";
    85         sout | "\t N/A";
     231        BlockCoroutineCreateDelete( NoOfTimes );
     232        DynamicCoroutineCreateDelete( NoOfTimes );
    86233        {
    87234                CoroutineResume resumer = { NoOfTimes };
    88235                resumer(&resumer);
    89236        }
    90         sout | "\t N/A";
    91 
     237        sout | endl;
     238
     239        sout | "task\t";
     240        BlockTaskCreateDelete( NoOfTimes );
     241        DynamicTaskCreateDelete( NoOfTimes );
     242        {
     243                scoped(ContextSwitch) dummy = { (int)NoOfTimes };               // context switch
     244        }
    92245        sout | "\t" | endl;
    93246}
Note: See TracChangeset for help on using the changeset viewer.