-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata_bench_test.go
More file actions
77 lines (61 loc) · 1.32 KB
/
Copy pathmetadata_bench_test.go
File metadata and controls
77 lines (61 loc) · 1.32 KB
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
package wal
import (
"context"
"testing"
)
func BenchmarkFileWALStatePublishAtomic(b *testing.B) {
benchmarkFileWALStatePublish(b, true)
}
func BenchmarkFileWALStatePublishInPlace(b *testing.B) {
benchmarkFileWALStatePublish(b, false)
}
func benchmarkFileWALStatePublish(
b *testing.B,
atomicPublish bool,
) {
if !supportsWALSynced() {
b.Skip("Synced WAL is unavailable on this platform")
}
metadata, err := openFileMetadata(
context.Background(),
testFileWALConfig(secureWALBenchmarkDirectory(b)),
)
if err != nil {
b.Fatal(err)
}
defer closeTest(b, metadata.close)
state := metadata.state
state.Generation++
if err := metadata.publishState(state); err != nil {
b.Fatal(err)
}
metadata.state = state
syncsBefore, _ := metadata.fileSystem.syncStats()
b.ReportAllocs()
b.SetBytes(walStateBytes)
b.ResetTimer()
for b.Loop() {
state.Generation++
if atomicPublish {
err = metadata.publishAtomic(
walStateFilename(state.Generation),
walStateTempFilename(state.Generation),
encodeWALState(state),
)
} else {
err = metadata.publishState(state)
}
if err != nil {
b.Fatal(err)
}
metadata.state = state
}
b.StopTimer()
syncsAfter, _ := metadata.fileSystem.syncStats()
if b.N != 0 {
b.ReportMetric(
float64(syncsAfter-syncsBefore)/float64(b.N),
"syncs/op",
)
}
}