mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-24 02:16:55 +08:00
benchmark test added for predictability
Signed-off-by: nikzayn <nikhilvaidyar1997@gmail.com>
This commit is contained in:
parent
b2152d01bb
commit
de169b5cdf
1 changed files with 32 additions and 0 deletions
32
12-optimizations/91-cpu-caches/predictability/main_test.go
Normal file
32
12-optimizations/91-cpu-caches/predictability/main_test.go
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
var global int64
|
||||||
|
|
||||||
|
const n = 1_000_000
|
||||||
|
|
||||||
|
func BenchmarkLinkedList(b *testing.B) {
|
||||||
|
var local int64
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
b.StopTimer()
|
||||||
|
nodes := make([]node, n)
|
||||||
|
for i := 0; i < n-1; i++ {
|
||||||
|
nodes[i].next = &nodes[i+1]
|
||||||
|
}
|
||||||
|
b.StartTimer()
|
||||||
|
local = linkedList(&nodes[0])
|
||||||
|
}
|
||||||
|
global = local
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSum2(b *testing.B) {
|
||||||
|
var local int64
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
b.StopTimer()
|
||||||
|
s := make([]int64, n)
|
||||||
|
b.StartTimer()
|
||||||
|
local = sum2(s)
|
||||||
|
}
|
||||||
|
global = local
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue