Created
June 20, 2013 03:30
-
-
Save titanous/5820101 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 main | |
import ( | |
"crypto/rand" | |
"testing" | |
) | |
type item struct { | |
A, B, C string | |
} | |
var items []item | |
var strings []string | |
func BenchmarkIteration(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for i, it := range items { | |
if strings[i] == it.A || strings[i] == it.B || strings[i] == it.C { | |
b.Log("collision!") | |
} | |
} | |
} | |
} | |
const N = 1000 | |
func init() { | |
items = make([]item, N) | |
strings = make([]string, N) | |
r := make([]byte, 400) | |
for i := 0; i < N; i++ { | |
rand.Reader.Read(r) | |
strings[i] = string(r[:100]) | |
items[i] = item{string(r[100:200]), string(r[200:300]), string(r[300:])} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment