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

ADTast-experimental
Last change on this file since cec2551 was cec2551, checked in by caparson <caparson@…>, 15 months ago

added cfa benchmarks

  • Property mode set to 100644
File size: 1.8 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    // printf("starting\n");
55
56    executor e{ 0, 1, 1, false, 1 };
57
58    start_actor_system( e );
59
60    start_time = bench_time();
61
62    // printf("started\n");
63
64    derived_msg * d_msg = malloc();
65    (*d_msg){};
66    derived_actor * d_actor = malloc();
67    (*d_actor){};
68    *d_actor << *d_msg;
69
70    // printf("stopping\n");
71
72    stop_actor_system();
73   
74    // uint64_t end_time = bench_time();
75
76    // printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) ); // s
77
78    // printf("%.2f\n", ((double)(end_time - start_time)) / ((double)Times) ); // ns
79
80    // printf("stopped\n");
81
82    return 0;
83}
Note: See TracBrowser for help on using the repository browser.