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