llama.go
llama.go copied to clipboard
Use builtin copy function
Feature Request
For copying slices like here the bultin copy function should be used. Wrote a simple benchmark test which shows it is ~4 times faster
package main
import (
"testing"
)
func VecCopyFP32(n uint32, dst, src []float32) {
for i := uint32(0); i < n; i++ {
dst[i] = src[i]
}
}
func BenchmarkVecCopyFP32(b *testing.B) {
var n uint32 = 1 << 20
src := make([]float32, n)
dst := make([]float32, n)
b.ResetTimer()
for i := 0; i < b.N; i++ {
VecCopyFP32(n, dst, src)
}
}
func BenchmarkCopyBuiltinUint(b *testing.B) {
var n uint32 = 1 << 20
src := make([]float32, n)
dst := make([]float32, n)
b.ResetTimer()
for i := 0; i < b.N; i++ {
copy(dst[:int(n)], src[:int(n)])
}
}