From d9caac373771d868e508d835ebc3294a9a611c50 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Sat, 17 Feb 2018 13:40:32 -0800 Subject: [PATCH] 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 --- godoc/dirtrees_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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) + } +}