Skip to content

Commit

Permalink
godoc: add benchmark for directory scan
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kevinburke committed Apr 15, 2018
1 parent 327197e commit d9caac3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions godoc/dirtrees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package godoc

import (
"go/build"
"path/filepath"
"runtime"
"sort"
"testing"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit d9caac3

Please sign in to comment.