-
-
Save win0err/18bb29aa1d32733360cfa03aa47af499 to your computer and use it in GitHub Desktop.
Скорость копирования памяти
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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