1
0
mirror of https://github.com/golang/go synced 2024-11-18 04:14:49 -07:00

godoc: add benchmark for directory scan

I'd like to propose changes to the directory scanner implementation,
and it would be good to be able to measure how changes compare in
terms of allocations and time taken.

Change-Id: I4ff4bbd38b5e3522f50d31473f2ac607bb0de802
Reviewed-on: https://go-review.googlesource.com/94904
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Kevin Burke 2018-02-17 13:40:32 -08:00
parent 327197e6b0
commit d9caac3737

View File

@ -5,6 +5,8 @@
package godoc
import (
"go/build"
"path/filepath"
"runtime"
"sort"
"testing"
@ -38,3 +40,25 @@ func processDir(t *testing.T, dir *Directory) {
t.Errorf("list: %v is not sorted\n", list)
}
}
func BenchmarkNewDirectory(b *testing.B) {
if testing.Short() {
b.Skip("not running tests requiring large file scan in short mode")
}
fsGate := make(chan bool, 20)
goroot := runtime.GOROOT()
rootfs := gatefs.New(vfs.OS(goroot), fsGate)
fs := vfs.NameSpace{}
fs.Bind("/", rootfs, "/", vfs.BindReplace)
for _, p := range filepath.SplitList(build.Default.GOPATH) {
fs.Bind("/src/golang.org", gatefs.New(vfs.OS(p), fsGate), "/src/golang.org", vfs.BindAfter)
}
b.ResetTimer()
b.ReportAllocs()
for tries := 0; tries < b.N; tries++ {
corpus := NewCorpus(fs)
corpus.newDirectory("/", -1)
}
}