Skip to content

Commit f4026d6

Browse files
committed
scripts/bench_comp: fixup benchmark script
1 parent bc5b513 commit f4026d6

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

scripts/bench_comp.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"flag"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"log"
98
"os"
109
"os/exec"
@@ -17,29 +16,24 @@ func init() {
1716
log.SetFlags(log.LstdFlags | log.Lshortfile)
1817
}
1918

20-
var Tests = []string{
21-
"filepath",
22-
"fastwalk",
23-
}
24-
2519
func main() {
26-
count := flag.Int("count", 5, "Run each test and benchmark n times")
20+
count := flag.Int("count", 10, "Run each test and benchmark n times")
2721
compCmd := flag.String("comp", "benchstat", "Benchmark comparison command")
2822
flag.Parse()
2923

3024
if _, err := exec.LookPath(*compCmd); err != nil {
3125
log.Fatalf("error: %v: %q\n", err, *compCmd)
3226
}
3327

34-
tmpdir, err := ioutil.TempDir("", "fastwalk-bench.*")
28+
tmpdir, err := os.MkdirTemp("", "fastwalk-bench.*")
3529
if err != nil {
3630
log.Fatal(err)
3731
}
3832

3933
runTest := func(name string) error {
4034
fmt.Println("##", name)
4135

42-
filename := filepath.Join(tmpdir, name+".txt")
36+
filename := filepath.Join(tmpdir, name)
4337
f, err := os.Create(filename)
4438
if err != nil {
4539
log.Fatal(err)
@@ -52,7 +46,6 @@ func main() {
5246
"-bench", `^BenchmarkWalkComparison$`,
5347
"-benchmem",
5448
"-count", strconv.Itoa(*count),
55-
"github.com/charlievieth/fastwalk",
5649
"-walkfunc", name,
5750
}
5851

@@ -72,18 +65,15 @@ func main() {
7265
return nil
7366
}
7467

75-
for _, name := range Tests {
76-
runTest(name)
77-
}
68+
runTest("filepath")
69+
runTest("fastwalk")
7870

7971
benchStat := func(from, to string) {
8072
fmt.Printf("## %s vs. %s\n", from, to)
81-
cmd := exec.Command(*compCmd,
82-
filepath.Join(tmpdir, from+".txt"),
83-
filepath.Join(tmpdir, to+".txt"),
84-
)
73+
cmd := exec.Command(*compCmd, from, to)
8574
cmd.Stderr = os.Stderr
8675
cmd.Stdout = os.Stdout
76+
cmd.Dir = tmpdir
8777
if err := cmd.Run(); err != nil {
8878
log.Fatalf("error running command: %q: %v\n", cmd.Args, err)
8979
}
@@ -94,7 +84,6 @@ func main() {
9484
fmt.Println("########################################################")
9585
fmt.Print("\n")
9686
benchStat("filepath", "fastwalk")
97-
benchStat("godirwalk", "fastwalk")
9887

9988
fmt.Printf("Temp: %s\n", tmpdir)
10089
}

0 commit comments

Comments
 (0)