Skip to content

Instantly share code, notes, and snippets.

@klauspost
Created April 29, 2015 10:32
Show Gist options
  • Save klauspost/ff88e22a02a7723abf02 to your computer and use it in GitHub Desktop.
Save klauspost/ff88e22a02a7723abf02 to your computer and use it in GitHub Desktop.
narray benchmark
package bench
import (
na "github.com/akualab/narray/na64"
"math"
"testing"
)
func benchmarkMin(bench *testing.B, size int, useGo bool) {
a := na.New(size)
b := na.New(size)
d := na.New(size)
for i := 0; i < size; i++ {
a.Data[i] = float64(i)
if i&1 == 0 {
b.Data[i] = float64(i)
} else {
b.Data[i] = float64(i) * -1
}
}
bench.ResetTimer()
bench.SetBytes(int64(size)) // Size is actually FLOPS
if useGo {
aa := a.Data
ba := b.Data
da := d.Data
for i := 0; i < bench.N; i++ {
for j := 0; j < size; j++ {
da[j] = math.Min(aa[j], ba[j])
}
}
} else {
for i := 0; i < bench.N; i++ {
d = na.MinArray(d, a, b)
}
}
}
func BenchmarkMinNarray1000(b *testing.B) { benchmarkMin(b, 1000, false) }
func BenchmarkMinGo1000(b *testing.B) { benchmarkMin(b, 1000, true) }
func BenchmarkMinNarray1000000(b *testing.B) { benchmarkMin(b, 1000000, false) }
func BenchmarkMinGo1000000(b *testing.B) { benchmarkMin(b, 1000000, true) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment