Ignore:
Timestamp:
May 5, 2017, 11:05:53 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
982ed5b, c10ee66
Parents:
45a4ea7 (diff), bd951f7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/benchmark/csv-data.c

    r45a4ea7 r4f9636f  
    11#include <fstream>
     2#include <monitor>
    23#include <stdlib>
    34#include <thread>
    45
    5 extern "C" {
    6 #include <unistd.h>                                     // sysconf
    7 #include <sys/times.h>                                  // times
    8 #include <time.h>
    9 }
    10 
    11 inline unsigned long long int Time() {
    12     timespec ts;
    13     clock_gettime(
    14 #if defined( __linux__ )
    15          CLOCK_THREAD_CPUTIME_ID,
    16 #elif defined( __freebsd__ )
    17          CLOCK_PROF,
    18 #elif defined( __solaris__ )
    19          CLOCK_HIGHRES,
    20 #else
    21     #error uC++ : internal error, unsupported architecture
    22 #endif
    23          &ts );
    24     return 1000000000LL * ts.tv_sec + ts.tv_nsec;
    25 } // Time
     6#include "bench.h"
    267
    278coroutine GreatSuspender {};
     
    4829#endif
    4930
    50 
    51 
     31//-----------------------------------------------------------------------------
     32// coroutine context switch
    5233long long int measure_coroutine() {
    5334        const unsigned int NoOfTimes = N;
     
    6748}
    6849
     50//-----------------------------------------------------------------------------
     51// thread context switch
    6952long long int measure_thread() {
    7053        const unsigned int NoOfTimes = N;
     
    8063}
    8164
     65//-----------------------------------------------------------------------------
     66// single monitor entry
     67monitor mon_t {};
     68void dummy( mon_t * mutex m ) {}
     69
     70long long int measure_1_monitor_entry() {
     71        const unsigned int NoOfTimes = N;
     72        long long int StartTime, EndTime;
     73        mon_t mon;
     74
     75        StartTime = Time();
     76        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
     77                dummy( &mon );
     78        }
     79        EndTime = Time();
     80
     81        return ( EndTime - StartTime ) / NoOfTimes;
     82}
     83
     84//-----------------------------------------------------------------------------
     85// multi monitor entry
     86void dummy( mon_t * mutex m1,  mon_t * mutex m2 ) {}
     87
     88long long int measure_2_monitor_entry() {
     89        const unsigned int NoOfTimes = N;
     90        long long int StartTime, EndTime;
     91        mon_t mon1, mon2;
     92
     93        StartTime = Time();
     94        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
     95                dummy( &mon1, &mon2 );
     96        }
     97        EndTime = Time();
     98
     99        return ( EndTime - StartTime ) / NoOfTimes;
     100}
     101
    82102int main()
    83103{
    84         sout | time(NULL) | ',' | measure_coroutine() | ',' | measure_thread() | endl;
     104        sout | time(NULL) | ',';
     105        sout | measure_coroutine() | ',';
     106        sout | measure_thread() | ',';
     107        sout | measure_1_monitor_entry() | ',';
     108        sout | measure_2_monitor_entry() | endl;
    85109}
Note: See TracChangeset for help on using the changeset viewer.