From 5a7988d556a2ef6531dca1c4ac2dc4e17112459f Mon Sep 17 00:00:00 2001 From: "Karrick S. McDermott" Date: Thu, 6 Feb 2020 18:26:26 +0000 Subject: [PATCH] bench.sh and benchmark_test.go --- bench.sh | 7 ++++ benchmark_test.go | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100755 bench.sh create mode 100644 benchmark_test.go diff --git a/bench.sh b/bench.sh new file mode 100755 index 0000000..b2ba374 --- /dev/null +++ b/bench.sh @@ -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 diff --git a/benchmark_test.go b/benchmark_test.go new file mode 100644 index 0000000..f052111 --- /dev/null +++ b/benchmark_test.go @@ -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 + } +}