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

Commit bcf8f9b

Browse files
committed
Update benchmark
1 parent 8b92f98 commit bcf8f9b

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

internal/gps/pkgtree/pkgtree_benchmark_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33
// license that can be found in the LICENSE file.
44
package pkgtree
55

6-
import "testing"
6+
import (
7+
"os"
8+
"path/filepath"
9+
"testing"
10+
)
711

812
func BenchmarkListPackages(b *testing.B) {
913
b.StopTimer()
1014

11-
j := func(s ...string) string {
12-
return testDir(b, s...)
13-
}
14-
15-
table := []string{
16-
"dotgodir",
17-
"buildtag",
18-
"varied",
15+
cwd, err := os.Getwd()
16+
if err != nil {
17+
b.Fatal(err)
1918
}
19+
root := filepath.Join(cwd, "..", "..", "..")
2020

2121
b.StartTimer()
2222

23-
for _, name := range table {
24-
for n := 0; n < b.N; n++ {
25-
ListPackages(j(name), name)
23+
for n := 0; n < b.N; n++ {
24+
_, err := ListPackages(root, "github.com/golang/dep")
25+
if err != nil {
26+
b.Error(err)
2627
}
2728
}
2829
}

internal/gps/pkgtree/pkgtree_test.go

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

475-
func testDir(t testing.TB, s ...string) string {
476-
srcdir := filepath.Join(getTestdataRootDir(t), "src")
477-
return filepath.Join(srcdir, filepath.Join(s...))
478-
}
479-
480475
func TestListPackages(t *testing.T) {
476+
srcdir := filepath.Join(getTestdataRootDir(t), "src")
481477
j := func(s ...string) string {
482-
return testDir(t, s...)
478+
return filepath.Join(srcdir, filepath.Join(s...))
483479
}
484480

485481
table := map[string]struct {
@@ -1980,7 +1976,7 @@ func TestToReachMapFilterDot(t *testing.T) {
19801976
}
19811977
}
19821978

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

0 commit comments

Comments
 (0)