Skip to content

Commit cd652a1

Browse files
author
Jeroen Demeyer
committed
[Go] add BenchmarkBuildAllocations
1 parent 7106d86 commit cd652a1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/go_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,3 +2573,21 @@ func BenchmarkBuildGold(b *testing.B) {
25732573
bldr.Finish(mon)
25742574
}
25752575
}
2576+
2577+
// Benchmark adding 130 bytes, one by one.
2578+
// Unlike BenchmarkBuildGold, we create a new builder every time,
2579+
// to test the performance of growing the buffer.
2580+
func BenchmarkBuildAllocations(b *testing.B) {
2581+
b.SetBytes(130)
2582+
b.ReportAllocs()
2583+
b.ResetTimer()
2584+
for i := 0; i < b.N; i++ {
2585+
bldr := flatbuffers.NewBuilder(0)
2586+
for j := 0; j < 130; j++ {
2587+
bldr.PrependByte(byte(j))
2588+
}
2589+
if len(bldr.Bytes) != 256 {
2590+
b.Fatalf("expected buffer size=256, got %d", len(bldr.Bytes))
2591+
}
2592+
}
2593+
}

0 commit comments

Comments
 (0)