-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
46 lines (42 loc) · 1011 Bytes
/
bench_test.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
package main
import (
"bytes"
"log"
"os/exec"
"testing"
"aslevy.com/go-doc/internal/benchmark"
)
func BenchmarkDirsNext(b *testing.B) {
var (
pkg Dir
ok bool
)
benchmark.Run(b, nil, func() {
dirs := newDirs()
for {
pkg, ok = dirs.Next()
if !ok {
return
}
}
})
b.Log("pkg: ", pkg, "ok: ", ok)
}
func newDirs(extra ...Dir) Dirs {
if buildCtx.GOROOT == "" {
stdout, err := exec.Command("go", "env", "GOROOT").Output()
if err != nil {
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
log.Fatalf("failed to determine GOROOT: $GOROOT is not set and 'go env GOROOT' failed:\n%s", ee.Stderr)
}
log.Fatalf("failed to determine GOROOT: $GOROOT is not set and could not run 'go env GOROOT':\n\t%s", err)
}
buildCtx.GOROOT = string(bytes.TrimSpace(stdout))
}
dirs.hist = make([]Dir, 0, 1000)
dirs.hist = append(dirs.hist, extra...)
dirs.scan = make(chan Dir)
// log.Println("code roots:", codeRoots())
go dirs.walk(codeRoots())
return dirs
}