Created
August 16, 2022 15:17
-
-
Save misberner/69a28f5f0206a6c98b66608a6aaaace4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package conformance | |
import ( | |
"google.golang.org/protobuf/proto" | |
"testing" | |
) | |
const ( | |
numObjects = 1000 | |
) | |
func BenchmarkOptimizedClone(b *testing.B) { | |
x := &TestAllTypesProto3{} | |
for i := 0; i < numObjects; i++ { | |
x.RepeatedNestedMessage = append(x.RepeatedNestedMessage, &TestAllTypesProto3_NestedMessage{A: int32(i)}) | |
} | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
_ = x.CloneVT() | |
} | |
} | |
func BenchmarkProtoCloneWholeObject(b *testing.B) { | |
x := &TestAllTypesProto3{} | |
for i := 0; i < numObjects; i++ { | |
x.RepeatedNestedMessage = append(x.RepeatedNestedMessage, &TestAllTypesProto3_NestedMessage{A: int32(i)}) | |
} | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
_ = proto.Clone(x) | |
} | |
} | |
func BenchmarkProtoCloneIndividualObjects(b *testing.B) { | |
x := &TestAllTypesProto3{} | |
for i := 0; i < numObjects; i++ { | |
x.RepeatedNestedMessage = append(x.RepeatedNestedMessage, &TestAllTypesProto3_NestedMessage{A: int32(i)}) | |
} | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
y := &TestAllTypesProto3{ | |
RepeatedNestedMessage: make([]*TestAllTypesProto3_NestedMessage, len(x.RepeatedNestedMessage)), | |
} | |
for j, v := range x.RepeatedNestedMessage { | |
y.RepeatedNestedMessage[j] = proto.Clone(v).(*TestAllTypesProto3_NestedMessage) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results: