diff --git a/godoc/dirtrees_test.go b/godoc/dirtrees_test.go index c8e8827a88..9727206ec2 100644 --- a/godoc/dirtrees_test.go +++ b/godoc/dirtrees_test.go @@ -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) + } +}