source: doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/dynamic.cfa @ fd0a9bf

Last change on this file since fd0a9bf was 05956d21, checked in by caparsons <caparson@…>, 17 months ago

refactored benchmarks to use actor bar operator

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6#include "bench.hfa"
7
8int Times = 1000000;                                                            // default values
9
10struct derived_actor {
11    inline actor;
12};
13
14struct derived_msg {
15    inline message;
16    int cnt;
17};
18
19static inline void ?{}( derived_msg & this, int cnt ) {
20    ((message &) this){ Delete };
21    this.cnt = cnt;
22}
23static inline void ?{}( derived_msg & this ) { this{ 0 }; }
24
25uint64_t start_time;
26allocation receive( derived_actor & receiver, derived_msg & msg ) {
27    if ( msg.cnt >= Times ) {
28        printf("%.2f\n", ((double)(bench_time() - start_time)) / ((double)Times) ); // ns
29        return Delete;
30    }
31    derived_msg * d_msg = malloc();
32    (*d_msg){ msg.cnt + 1 };
33    derived_actor * d_actor = malloc();
34    (*d_actor){};
35    *d_actor | *d_msg;
36    return Delete;
37}
38
39int main( int argc, char * argv[] ) {
40    switch ( argc ) {
41          case 2:
42                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
43                        Times = atoi( argv[1] );
44                        if ( Times < 1 ) goto Usage;
45                } // if
46          case 1:                                                                                       // use defaults
47                break;
48          default:
49          Usage:
50                sout | "Usage: " | argv[0] | " [ times (> 0) ]";
51                exit( EXIT_FAILURE );
52        } // switch
53
54    executor e{ 0, 1, 1, false, 1 };
55
56    start_actor_system( e );
57
58    start_time = bench_time();
59
60    derived_msg * d_msg = malloc();
61    (*d_msg){};
62    derived_actor * d_actor = malloc();
63    (*d_actor){};
64    *d_actor | *d_msg;
65
66
67    stop_actor_system();
68   
69    // uint64_t end_time = bench_time();
70
71    // printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) ); // s
72
73    // printf("%.2f\n", ((double)(end_time - start_time)) / ((double)Times) ); // ns
74
75    return 0;
76}
Note: See TracBrowser for help on using the repository browser.