File tree 1 file changed +40
-0
lines changed 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "machine"
5
+ "runtime"
6
+ "sync"
7
+ "time"
8
+ )
9
+
10
+ const N = 500000
11
+ const Ngoro = 4
12
+
13
+ func main () {
14
+ start := time .Now ()
15
+ var wg sync.WaitGroup
16
+ wg .Add (Ngoro )
17
+ for i := 0 ; i < Ngoro ; i ++ {
18
+ go adder (& wg , N )
19
+ }
20
+ wg .Wait ()
21
+ elapsed := time .Since (start )
22
+ goroutineCtxSwitchOverhead := (elapsed / (Ngoro * N )).String ()
23
+
24
+ elapsedstr := elapsed .String ()
25
+ machine .LED .Configure (machine.PinConfig {Mode : machine .PinOutput })
26
+ for {
27
+ println ("bench:" , elapsedstr , "goroutine ctx switch:" , goroutineCtxSwitchOverhead )
28
+ machine .LED .High ()
29
+ time .Sleep (elapsed )
30
+ machine .LED .Low ()
31
+ time .Sleep (elapsed )
32
+ }
33
+ }
34
+
35
+ func adder (wg * sync.WaitGroup , num int ) {
36
+ for i := 0 ; i < num ; i ++ {
37
+ runtime .Gosched ()
38
+ }
39
+ wg .Done ()
40
+ }
You can’t perform that action at this time.
0 commit comments