mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-09 14:46:26 +00:00
Reduce allocations when reusing a Builder.
Add the function `Reset` to the Builder, which facilitates reuse of the underlying byte slice.
This commit is contained in:
@@ -43,7 +43,7 @@ GOPATH=${go_path} go test flatbuffers_test \
|
||||
--test.coverpkg=github.com/google/flatbuffers/go \
|
||||
--cpp_data=${test_dir}/monsterdata_test.mon \
|
||||
--out_data=${test_dir}/monsterdata_go_wire.mon \
|
||||
--test.bench=Build \
|
||||
--test.bench=. \
|
||||
--test.benchtime=3s \
|
||||
--fuzz=true \
|
||||
--fuzz_fields=4 \
|
||||
|
||||
@@ -1254,9 +1254,11 @@ func BenchmarkBuildGold(b *testing.B) {
|
||||
reuse_fred := []byte("Fred")
|
||||
|
||||
b.SetBytes(bytes_length)
|
||||
bldr := flatbuffers.NewBuilder(512)
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
bldr := flatbuffers.NewBuilder(0)
|
||||
bldr.Reset()
|
||||
|
||||
str := bldr.CreateByteString(reuse_str)
|
||||
test1 := bldr.CreateByteString(reuse_test1)
|
||||
test2 := bldr.CreateByteString(reuse_test2)
|
||||
|
||||
Reference in New Issue
Block a user