Skip to content

Commit

Permalink
[Go] add BenchmarkBuildAllocations
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Apr 22, 2024
1 parent 7106d86 commit cd652a1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2573,3 +2573,21 @@ func BenchmarkBuildGold(b *testing.B) {
bldr.Finish(mon)
}
}

// Benchmark adding 130 bytes, one by one.
// Unlike BenchmarkBuildGold, we create a new builder every time,
// to test the performance of growing the buffer.
func BenchmarkBuildAllocations(b *testing.B) {
b.SetBytes(130)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
bldr := flatbuffers.NewBuilder(0)
for j := 0; j < 130; j++ {
bldr.PrependByte(byte(j))
}
if len(bldr.Bytes) != 256 {
b.Fatalf("expected buffer size=256, got %d", len(bldr.Bytes))
}
}
}

0 comments on commit cd652a1

Please sign in to comment.