Skip to content

Commit

Permalink
maybe fix bench reproducibility
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed May 28, 2024
1 parent 10ed1f0 commit 5a760bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion godeltaprof/compat/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ func BenchmarkHeapCompression(b *testing.B) {
h := newHeapTestHelper()
fs := h.generateMemProfileRecords(512, 32)
b.ResetTimer()
nmutations := int(h.rng.Int63() % int64(len(fs)))
for i := 0; i < b.N; i++ {
_ = WriteHeapProto(h.dp, h.opt, io.Discard, fs, int64(runtime.MemProfileRate))
h.mutate(fs)
h.mutate(nmutations, fs)
}
}

Expand Down
3 changes: 2 additions & 1 deletion godeltaprof/compat/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ func BenchmarkHeapDelta(b *testing.B) {
fs := h.generateMemProfileRecords(512, 32)
builder := &noopBuilder{}
b.ResetTimer()
nmutations := int(h.rng.Int63() % int64(len(fs)))
for i := 0; i < b.N; i++ {
_ = h.dp.WriteHeapProto(builder, fs, int64(runtime.MemProfileRate))
h.mutate(fs)
h.mutate(nmutations, fs)
}
}

Expand Down
5 changes: 2 additions & 3 deletions godeltaprof/compat/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,9 @@ func (h *heapTestHelper) r(AllocObjects, AllocBytes, FreeObjects, FreeBytes int6
}
}

func (h *heapTestHelper) mutate(fs []runtime.MemProfileRecord) {
nmutations := int(h.rng.Int63() % int64(len(fs)))
func (h *heapTestHelper) mutate(n int, fs []runtime.MemProfileRecord) {
objSize := fs[0].AllocBytes / fs[0].AllocObjects
for j := 0; j < nmutations; j++ {
for j := 0; j < n; j++ {
idx := int(uint(h.rng.Int63())) % len(fs)
fs[idx].AllocObjects += 1
fs[idx].AllocBytes += objSize
Expand Down

0 comments on commit 5a760bf

Please sign in to comment.