source: doc/theses/colby_parsons_MMAth/benchmarks/actors/proto/SendStatic/GoSendStatic.go @ 5adf4f4

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

added caf/uC++/proto benchmarks

  • Property mode set to 100644
File size: 1.5 KB
Line 
1// https://github.com/asynkron/protoactor-go
2// https://pkg.go.dev/github.com/asynkron/protoactor-go/actor
3package main
4
5import (
6        "os"; "strconv"; "fmt"; "time"; "runtime"
7        "github.com/asynkron/protoactor-go/actor"
8)
9
10var Times int = 100_000_000;
11var start time.Time;
12var shake = make( chan string )
13var system * actor.ActorSystem
14
15type Msg struct { cnt int }
16var msg Msg
17type Send struct{}
18
19func ( state * Send ) Receive( context actor.Context ) {
20        switch context.Message().(type) {
21          case * Msg:
22                if msg.cnt >= Times  {
23                        fmt.Printf( "%v\n", int64(time.Since(start) / time.Duration(Times) / time.Nanosecond) );
24                        shake <- "hand"
25                        return;
26                } // if
27                //fmt.Printf( "Send %v\n", msg.cnt );
28                msg.cnt += 1;
29                system.Root.Send( context.Self(), &msg );
30          default:
31                // ignore actor.Started message
32        }
33}
34
35func usage() {
36        fmt.Printf( "Usage: %v [ times (> 0) ]\n", os.Args[0] );
37        os.Exit( 1 );
38}
39
40func main() {
41        switch len( os.Args ) {
42          case 2:
43                if os.Args[1] != "d" { Times, _ = strconv.Atoi( os.Args[1] ) }
44                if Times < 1 { usage(); }
45          case 1:                                                                                       // use defaults
46          default:
47                usage();
48        } // switch
49
50        runtime.GOMAXPROCS(1);
51        system = actor.NewActorSystem();
52        props := actor.PropsFromProducer( func() actor.Actor { return &Send{} } );
53        pid := system.Root.Spawn(props);
54        start = time.Now();
55        system.Root.Send( pid, &msg );
56        <- shake
57}
58
59// /usr/bin/time -f "%Uu %Ss %Er %Mkb" GoSendStatic
60
61// Local Variables: //
62// tab-width: 4 //
63// compile-command: "go build" //
64// End: //
Note: See TracBrowser for help on using the repository browser.