Created
July 12, 2016 00:28
-
-
Save kana-sama/55a828db72734fd35d2928892e0fd09d 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
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) | |
} | |
} |
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 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