Reuse gob.Encoder and Decoder in DeepCopy
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -106,3 +107,37 @@ func TestDeepCopyPointerSeparate(t *testing.T) {
|
||||
t.Errorf("deep copy wasn't deep: %#q %#q", x, y)
|
||||
}
|
||||
}
|
||||
|
||||
var result interface{}
|
||||
|
||||
func BenchmarkDeepCopy(b *testing.B) {
|
||||
table := []interface{}{
|
||||
map[string]string{},
|
||||
int(5),
|
||||
"hello world",
|
||||
struct {
|
||||
A, B, C struct {
|
||||
D map[string]int
|
||||
}
|
||||
X []int
|
||||
Y []byte
|
||||
}{},
|
||||
}
|
||||
|
||||
f := fuzz.New().RandSource(rand.NewSource(1)).NilChance(.5).NumElements(0, 100)
|
||||
for i := range table {
|
||||
out := table[i]
|
||||
obj := reflect.New(reflect.TypeOf(out)).Interface()
|
||||
f.Fuzz(obj)
|
||||
table[i] = obj
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
var r interface{}
|
||||
for i := 0; i < b.N; i++ {
|
||||
for j := range table {
|
||||
r, _ = DeepCopy(table[j])
|
||||
}
|
||||
}
|
||||
result = r
|
||||
}
|
||||
|
Reference in New Issue
Block a user