forked from karrick/godirwalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
85 lines (73 loc) · 1.51 KB
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
}
}