Created
September 3, 2020 14:11
-
-
Save sapphi-red/2de1653580ca1c2918039a886acc0035 to your computer and use it in GitHub Desktop.
prediction fail
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 prediction | |
import ( | |
"math/rand" | |
"testing" | |
) | |
func BenchmarkEvery(b *testing.B) { | |
howmany := 10000000 | |
out := [10000000]int{} | |
index := 0 | |
b.ResetTimer() | |
for howmany != 0 { | |
out[index] = rand.Int() | |
index += 1 | |
howmany-- | |
} | |
} | |
func BenchmarkOnlyOddPredictionFail(b *testing.B) { | |
howmany := 10000000 | |
out := [10000000]int{} | |
index := 0 | |
b.ResetTimer() | |
for howmany != 0 { | |
val := rand.Int() | |
if val%2 != 0 { | |
out[index] = val | |
index += 1 | |
} | |
howmany-- | |
} | |
} | |
func BenchmarkOnlyOddNonPrediction(b *testing.B) { | |
howmany := 10000000 | |
out := [10000000]int{} | |
index := 0 | |
b.ResetTimer() | |
for howmany != 0 { | |
val := rand.Int() | |
out[index] = val | |
index += val & 1 | |
howmany-- | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.youtube.com/watch?v=wlvKAT7SZIQ