-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathprofile.go
More file actions
68 lines (61 loc) · 1.06 KB
/
profile.go
File metadata and controls
68 lines (61 loc) · 1.06 KB
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
package main
import (
gotomic "../"
"runtime/pprof"
"runtime"
"math/rand"
"time"
"os"
)
type compInt int
func (self compInt) Compare(t gotomic.Thing) int {
if i, ok := t.(compInt); ok {
if i > self {
return 1
} else if i < self {
return -1
}
}
return 0
}
func work(h *gotomic.Treap, n int, do, done chan bool) {
<- do
keys := make([]compInt, n)
for i := 0; i < n; i++ {
k := compInt(rand.Int())
keys[i] = k
h.Put(k, i)
}
for i := 0; i < n; i++ {
h.Get(keys[i])
}
done <- true
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
rand.Seed(time.Now().UnixNano())
f, err := os.Create("cpuprofile")
if err != nil {
panic(err.Error())
}
f2, err := os.Create("memprofile")
if err != nil {
panic(err.Error())
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
defer pprof.WriteHeapProfile(f2)
h := gotomic.NewTreap()
do := make(chan bool)
done := make(chan bool)
n := 100000
go work(h, n, do, done)
go work(h, n, do, done)
go work(h, n, do, done)
go work(h, n, do, done)
close(do)
<- done
<- done
<- done
<- done
}