如题。
![image.png](https://static.studygolang.com/210421/4b72f5a2c2de7f954808bc9db763e977.png)
![image.png](https://static.studygolang.com/210421/db2e173184f1337d77cb2455074358f6.png)
看官方文档没看出有什么区别,求大佬指教。。。
```
package copy
import (
"reflect"
"testing"
)
func BenchmarkBuiltinCopy(b *testing.B) {
src := make([]int, 1000)
for i := 0; i < 1000; i ++ {
src[i] = i
}
dst := make([]int, 1000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
copy(dst, src)
}
}
func BenchmarkReflectCopy(b *testing.B) {
src := make([]int, 1000)
for i := 0; i < 1000; i ++ {
src[i] = i
}
dst := make([]int, 1000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
reflect.Copy(reflect.ValueOf(dst), reflect.ValueOf(src))
}
}
```
![image.png](https://static.studygolang.com/210421/f36bab0c99fbb20c49ca7f77f3bb36d9.png)
大概测了下,内建copy函数性能要更好一点。
#1