-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
71 lines (62 loc) · 1.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"github.com/antonikonovalov/nn/drive/pool/each"
"github.com/antonikonovalov/nn/drive/pool/oneof"
"sync"
"time"
)
func main() {
t := time.Now()
for i := 0; i < 1000; i++ {
func() int {
return i
}()
}
println(`SPEED ITER 1000 i:`, time.Since(t).String())
t = time.Now()
epool := each.MakePool(1000)
println(`UP EACH 1000 procs:`, time.Since(t).String())
wg := &sync.WaitGroup{}
wg.Add(1000)
tp := time.Now()
for i := 0; i < 1000; i++ {
epool.Go(func() int {
defer wg.Done()
return i
})
}
wg.Wait()
println(`PROC EACH 1000 tasks:`, time.Since(tp).String())
t = time.Now()
epool.Stop()
println(`DOWN EACH 1000 procs:`, time.Since(t).String())
//-------------------------------------------------------
t = time.Now()
opool := oneof.MakePool(1000)
println(`UP ONEOF 1000 procs:`, time.Since(t).String())
wgo := &sync.WaitGroup{}
wgo.Add(1000)
tpo := time.Now()
for i := 0; i < 1000; i++ {
opool.Go(func() int {
defer wgo.Done()
return i
})
}
wgo.Wait()
println(`PROC ONEOF 1000 tasks:`, time.Since(tpo).String())
t = time.Now()
opool.Stop()
println(`DOWN ONEOF 1000 procs:`, time.Since(t).String())
wgb := &sync.WaitGroup{}
wgb.Add(1000)
tpb := time.Now()
for i := 0; i < 1000; i++ {
go func() int {
defer wgb.Done()
return i
}()
}
wgb.Wait()
println(`NATIVE MIX - UP/DOWN/PROC 1000 tasks:`, time.Since(tpb).String())
}