Skip to content

Commit

Permalink
bench.sh and benchmark_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
karrick committed Feb 6, 2020
1 parent 4c58500 commit 5a7988d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# for version in v1.9.1 v1.10.0 v1.10.3 v1.10.12 v1.11.2 v1.11.3 v1.12.0 v1.13.1 v1.14.0 v1.14.1 ; do
for version in v1.10.12 v1.14.1 v1.15.2 ; do
echo "### $version" > $version.txt
git checkout -- go.mod && git checkout $version && go test -run=NONE -bench=Benchmark2 >> $version.txt || exit 1
done
85 changes: 85 additions & 0 deletions benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package godirwalk

import (
"path/filepath"
"testing"
)

const benchRoot = "/mnt/ram_disk/src"

var scratch []byte
var largeDirectory string

func init() {
scratch = make([]byte, MinimumScratchBufferSize)
largeDirectory = filepath.Join(benchRoot, "linkedin/dashboards")
}

func Benchmark2ReadDirentsGodirwalk(b *testing.B) {
var count int

for i := 0; i < b.N; i++ {
actual, err := ReadDirents(largeDirectory, scratch)
if err != nil {
b.Fatal(err)
}
count += len(actual)
}

_ = count
}

func Benchmark2ReadDirnamesGodirwalk(b *testing.B) {
var count int

for i := 0; i < b.N; i++ {
actual, err := ReadDirnames(largeDirectory, scratch)
if err != nil {
b.Fatal(err)
}
count += len(actual)
}

_ = count
}

func Benchmark2GodirwalkSorted(b *testing.B) {
for i := 0; i < b.N; i++ {
var length int
err := Walk(benchRoot, &Options{
Callback: func(name string, _ *Dirent) error {
if name == "skip" {
return filepath.SkipDir
}
length += len(name)
return nil
},
ScratchBuffer: scratch,
})
if err != nil {
b.Errorf("GOT: %v; WANT: nil", err)
}
_ = length
}
}

func Benchmark2GodirwalkUnsorted(b *testing.B) {
for i := 0; i < b.N; i++ {
var length int
err := Walk(benchRoot, &Options{
Callback: func(name string, _ *Dirent) error {
if name == "skip" {
return filepath.SkipDir
}
length += len(name)
return nil
},
ScratchBuffer: scratch,
Unsorted: true,
})
if err != nil {
b.Errorf("GOT: %v; WANT: nil", err)
}
_ = length
}
}

0 comments on commit 5a7988d

Please sign in to comment.