A case:
func iterateAndCopy(slice []T, p *T) {
for _, v := range slice {
*p = v
}
}
func Benchmark_CopyCosts(b *testing.B) {
b.Run("bool-4", func(b *testing.B){
iterateAndCopy(make([]bool, 4), new(bool))
})
b.Run("int32-4", func(b *testing.B){
iterateAndCopy(make([]int32, 4), new(int32))
})
b.Run("int64-4", func(b *testing.B){
iterateAndCopy(make([]int64, 4), new(int64))
})
b.Run("[128]int-4", func(b *testing.B){
iterateAndCopy(make([][128]int64, 4), new([128]int64))
})
b.Run("struct{a,b,c,d int32}-100", func(b *testing.B){
iterateAndCopy(make([]struct{a,b,c,d int32}, 100),
new(struct{a,b,c,d int32}))
})
b.Run("bool-100", func(b *testing.B){
iterateAndCopy(make([]bool, 100), new(bool))
})
b.Run("int32-100", func(b *testing.B){
iterateAndCopy(make([]int32, 100), new(int32))
})
b.Run("int64-100", func(b *testing.B){
iterateAndCopy(make([]int64, 100), new(int64))
})
b.Run("[128]int-100", func(b *testing.B){
iterateAndCopy(make([][128]int64, 100), new([128]int64))
})
b.Run("struct{a,b,c,d int32}-100", func(b *testing.B){
iterateAndCopy(make([]struct{a,b,c,d int32}, 100),
new(struct{a,b,c,d int32}))
})
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.