Skip to content

Instantly share code, notes, and snippets.

@win0err win0err/process-vectors-copy.go Secret
Created Feb 18, 2018

Embed
What would you like to do?
Скорость копирования памяти
package main
import (
"fmt"
"math"
"time"
)
type V4 [4]float32
const (
numVectors = 8 * 1024 * 1024
)
func benchmark(f func()) {
best := math.MaxFloat64
for i := 0; i < 100; i++ {
start := time.Now()
f()
end := time.Now()
elapsed := end.Sub(start).Seconds()
if elapsed < best {
best = elapsed
}
}
fmt.Printf("%.0fms\n", best*1000)
}
func main() {
data := make([]V4, numVectors)
for i := range data {
data[i] = V4{1, 2, 3, 4}
}
benchmark(func() { copy(data, data) })
}
go build -o process-vectors-copy && ./process-vectors-copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.