Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save j16r/a62a577586d9e65518f2 to your computer and use it in GitHub Desktop.

Select an option

Save j16r/a62a577586d9e65518f2 to your computer and use it in GitHub Desktop.
package sets
import "testing"
func BenchmarkUnitSet(b *testing.B) {
for i := 0; i < b.N; i++ {
values := make(map[int]struct{})
for j := 0; j < 1000; j++ {
values[j] = struct{}{}
}
for j := 0; j < 1000; j++ {
_ = values[j]
}
}
}
func BenchmarkBoolSet(b *testing.B) {
for i := 0; i < b.N; i++ {
values := make(map[int]bool)
for j := 0; j < 1000; j++ {
values[j] = true
}
for j := 0; j < 1000; j++ {
_ = values[j]
}
}
}
@j16r
Copy link
Copy Markdown
Author

j16r commented Aug 21, 2015

testing: warning: no tests to run
PASS
BenchmarkUnitSet-8         10000            138503 ns/op           47194 B/op         96 allocs/op
BenchmarkBoolSet-8         10000            141235 ns/op           55261 B/op         96 allocs/op
ok      command-line-arguments  2.836s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment