1 | // https://github.com/asynkron/protoactor-go |
---|
2 | // https://pkg.go.dev/github.com/asynkron/protoactor-go/actor |
---|
3 | package main |
---|
4 | |
---|
5 | import ( |
---|
6 | "os"; "strconv"; "fmt"; "time"; "runtime" |
---|
7 | "github.com/asynkron/protoactor-go/actor" |
---|
8 | ) |
---|
9 | |
---|
10 | var Times int = 100_000_000; |
---|
11 | var start time.Time; |
---|
12 | var shake = make( chan string ) |
---|
13 | var system * actor.ActorSystem |
---|
14 | |
---|
15 | type Msg struct { cnt int } |
---|
16 | var msg Msg |
---|
17 | type Send struct{} |
---|
18 | |
---|
19 | func ( 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 | |
---|
35 | func usage() { |
---|
36 | fmt.Printf( "Usage: %v [ times (> 0) ]\n", os.Args[0] ); |
---|
37 | os.Exit( 1 ); |
---|
38 | } |
---|
39 | |
---|
40 | func 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: // |
---|