Skip to content

Instantly share code, notes, and snippets.

@kana-sama
Created July 12, 2016 00:28
Show Gist options
  • Save kana-sama/55a828db72734fd35d2928892e0fd09d to your computer and use it in GitHub Desktop.
Save kana-sama/55a828db72734fd35d2928892e0fd09d to your computer and use it in GitHub Desktop.
func longFunc(x float64) float64 {
var sum float64 = 0
for i := float64(0); i < x; i++ {
sum = math.Sin(i)
}
return sum
}
func benchmarkFold(f fold, b *testing.B) {
var s = make(slice, 100)
for i := range s {
s[i] = 100 * float64(i)
}
for n := 0; n < b.N; n++ {
f(s, longFunc)
}
}
$ go test -bench . -benchtime 1s
PASS
BenchmarkFoldFast-4 300 4928328 ns/op
BenchmarkFoldParallel-4 300 4870866 ns/op
BenchmarkFoldSimple-4 100 18261889 ns/op
ok github.com/the-varlog/fold 5.775s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment