-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuC++SendBasic.cc
More file actions
65 lines (57 loc) · 1.68 KB
/
uC++SendBasic.cc
File metadata and controls
65 lines (57 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
using namespace std;
#include <chrono>
using namespace chrono;
#include <uActor.h>
int Times = 1'000'000; // default values
time_point<steady_clock> starttime;
struct Msg : public uActor::Message {} msg; // regular message
struct TMsg : public uActor::TraceMsg {} tmsg; // traceable message
_Actor Trace {
enum { Msgs = 100 };
int times = 0, mcnt = 0;
Allocation msgSend( Message & ) {
if ( times >= Times ) {
cout << Times << ' ' << (steady_clock::now() - starttime).count() / Times / Msgs << "ns" << endl;
return Finished;
} // if
for ( int i = 0; i < Msgs; i += 1 ) *this | msg; // send self N messages
become( &Trace::msgReceive );
return Nodelete;
}
Allocation msgReceive( Message & ) {
mcnt += 1;
if ( mcnt == Msgs ) { // receive N messages and then toggle state
times += 1;
mcnt = 0;
become( &Trace::msgSend );
*this | msg;
} // if
return Nodelete;
}
public:
Trace() { become( &Trace::msgSend ); }
}; // Trace
int main( int argc, char * argv[] ) {
switch ( argc ) {
case 2:
if ( strcmp( argv[1], "d" ) != 0 ) { Times = stoi( argv[1] ); }
if ( Times < 1 ) goto Usage;
case 1: // use defaults
break;
default:
Usage:
cerr << "Usage: " << argv[0] << " [ times (> 0) ]" << endl;
exit( EXIT_FAILURE );
} // switch
uActor::start(); // start actor system
Trace trace;
starttime = steady_clock::now();
trace | msg;
uActor::stop(); // wait for all actors to terminate
// malloc_stats();
} // main
// /usr/bin/time -f "%Uu %Ss %Er %Mkb" a.out
// Local Variables: //
// compile-command: "u++-work -g -Wall -Wextra -O3 -nodebug -DNDEBUG -multi uC++SendBasic.cc" //
// End: //