Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 8b92f98

Browse files
committed
Add benchmark
1 parent 07cd3a2 commit 8b92f98

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
package pkgtree
5+
6+
import "testing"
7+
8+
func BenchmarkListPackages(b *testing.B) {
9+
b.StopTimer()
10+
11+
j := func(s ...string) string {
12+
return testDir(b, s...)
13+
}
14+
15+
table := []string{
16+
"dotgodir",
17+
"buildtag",
18+
"varied",
19+
}
20+
21+
b.StartTimer()
22+
23+
for _, name := range table {
24+
for n := 0; n < b.N; n++ {
25+
ListPackages(j(name), name)
26+
}
27+
}
28+
}

internal/gps/pkgtree/pkgtree_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,14 @@ func TestListPackagesNoDir(t *testing.T) {
472472
}
473473
}
474474

475-
func TestListPackages(t *testing.T) {
475+
func testDir(t testing.TB, s ...string) string {
476476
srcdir := filepath.Join(getTestdataRootDir(t), "src")
477+
return filepath.Join(srcdir, filepath.Join(s...))
478+
}
479+
480+
func TestListPackages(t *testing.T) {
477481
j := func(s ...string) string {
478-
return filepath.Join(srcdir, filepath.Join(s...))
482+
return testDir(t, s...)
479483
}
480484

481485
table := map[string]struct {
@@ -1976,7 +1980,7 @@ func TestToReachMapFilterDot(t *testing.T) {
19761980
}
19771981
}
19781982

1979-
func getTestdataRootDir(t *testing.T) string {
1983+
func getTestdataRootDir(t testing.TB) string {
19801984
cwd, err := os.Getwd()
19811985
if err != nil {
19821986
t.Fatal(err)

0 commit comments

Comments
 (0)