1 | #include <iostream>
|
---|
2 | using namespace std;
|
---|
3 | #include <chrono>
|
---|
4 | using namespace chrono;
|
---|
5 |
|
---|
6 | #include "caf/actor_ostream.hpp"
|
---|
7 | #include "caf/caf_main.hpp"
|
---|
8 | #include "caf/event_based_actor.hpp"
|
---|
9 | using namespace caf;
|
---|
10 |
|
---|
11 | int Times = 10'000'000; // default values
|
---|
12 | time_point<steady_clock> starttime;
|
---|
13 |
|
---|
14 | class Send : public event_based_actor {
|
---|
15 | public:
|
---|
16 | Send( caf::actor_config & cfg ) : event_based_actor( cfg ) {}
|
---|
17 |
|
---|
18 | behavior make_behavior() override {
|
---|
19 | return {
|
---|
20 | [=]( int & cnt ) -> void {
|
---|
21 | if ( cnt >= Times ) {
|
---|
22 | aout(this) << (steady_clock::now() - starttime).count() / Times << endl;
|
---|
23 | this->quit();
|
---|
24 | return;
|
---|
25 | } // if
|
---|
26 | //aout(this) << cnt << endl;
|
---|
27 | this->send( this, cnt + 1 );
|
---|
28 | }
|
---|
29 | };
|
---|
30 | }
|
---|
31 | }; // Send
|
---|
32 |
|
---|
33 | void caf_main( actor_system & sys ) {
|
---|
34 | auto starter = sys.spawn<Send>();
|
---|
35 | starttime = steady_clock::now();
|
---|
36 | caf::anon_send( starter, 0 );
|
---|
37 | } // caf_main
|
---|
38 |
|
---|
39 | int main( int argc, char * argv[] ) {
|
---|
40 | switch ( argc ) {
|
---|
41 | case 2:
|
---|
42 | if ( strcmp( argv[1], "d" ) != 0 ) { Times = stoi( argv[1] ); }
|
---|
43 | if ( Times < 1 ) goto Usage;
|
---|
44 | case 1: // use defaults
|
---|
45 | break;
|
---|
46 | default:
|
---|
47 | Usage:
|
---|
48 | cerr << "Usage: " << argv[0] << " [ times (> 0) ]" << endl;
|
---|
49 | exit( EXIT_FAILURE );
|
---|
50 | } // switch
|
---|
51 |
|
---|
52 | caf::exec_main_init_meta_objects<>();
|
---|
53 | caf::core::init_global_meta_objects();
|
---|
54 | return caf::exec_main<>(caf_main, argc, argv);
|
---|
55 | } // main
|
---|
56 | //CAF_MAIN()
|
---|
57 |
|
---|
58 | // /usr/bin/time -f "%Uu %Ss %Er %Mkb" a.out
|
---|
59 |
|
---|
60 | // Local Variables: //
|
---|
61 | // compile-command: "g++-10 -O3 -Wall -std=c++17 -ICAF/actor-framework/libcaf_core -ICAF/actor-framework/libcaf_core/caf -ICAF/actor-framework/build/libcaf_core -LCAF/actor-framework/build/libcaf_core -LCAF/actor-framework/build/libcaf_io CAFSendStatic.cpp -lcaf_io -lcaf_core -Wl,-rpath=CAF/actor-framework/build/libcaf_core" //
|
---|
62 | // End: //
|
---|