source: doc/theses/colby_parsons_MMath/benchmarks/actors/proto/SendStatic/GoSendStatic.go

Last change on this file was f945fa7, checked in by Peter A. Buhr <pabuhr@…>, 13 hours ago

fix spelling mistake in directory name

  • 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.