Skip to content

Commit ebdd069

Browse files
committed
Add copy benchmark
Signed-off-by: Derek McGowan <[email protected]>
1 parent cec82ed commit ebdd069

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

fs/copy_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package fs
1919
import (
2020
_ "crypto/sha256"
2121
"fmt"
22+
"os"
2223
"testing"
2324
"time"
2425

@@ -89,3 +90,37 @@ func testCopy(t testing.TB, apply fstest.Applier) error {
8990

9091
return fstest.CheckDirectoryEqual(t1, t2)
9192
}
93+
94+
func BenchmarkLargeCopy100MB(b *testing.B) {
95+
benchmarkLargeCopyFile(b, 100*1024*1024)
96+
}
97+
98+
func BenchmarkLargeCopy1GB(b *testing.B) {
99+
benchmarkLargeCopyFile(b, 1024*1024*1024)
100+
}
101+
102+
func benchmarkLargeCopyFile(b *testing.B, size int64) {
103+
b.StopTimer()
104+
base := b.TempDir()
105+
apply := fstest.Apply(
106+
fstest.CreateRandomFile("/large", time.Now().UnixNano(), size, 0o644),
107+
)
108+
if err := apply.Apply(base); err != nil {
109+
b.Fatal("failed to apply changes:", err)
110+
}
111+
112+
for i := 0; i < b.N; i++ {
113+
copied := b.TempDir()
114+
b.StartTimer()
115+
if err := CopyDir(copied, base); err != nil {
116+
b.Fatal("failed to copy:", err)
117+
}
118+
b.StopTimer()
119+
if i == 0 {
120+
if err := fstest.CheckDirectoryEqual(base, copied); err != nil {
121+
b.Fatal("check failed:", err)
122+
}
123+
}
124+
os.RemoveAll(copied)
125+
}
126+
}

0 commit comments

Comments
 (0)