Skip to content

Instantly share code, notes, and snippets.

@win0err
Created February 18, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save win0err/18bb29aa1d32733360cfa03aa47af499 to your computer and use it in GitHub Desktop.
Save win0err/18bb29aa1d32733360cfa03aa47af499 to your computer and use it in GitHub Desktop.
Скорость копирования памяти
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