Skip to content

Use builtin copy function #32

Description

@martinscholz83

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)])
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions