Skip to content

Instantly share code, notes, and snippets.

@titanous
Created June 20, 2013 03:30
Show Gist options
  • Save titanous/5820101 to your computer and use it in GitHub Desktop.
Save titanous/5820101 to your computer and use it in GitHub Desktop.
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