Skip to content

Instantly share code, notes, and snippets.

@mark-rushakoff
Created August 16, 2013 22:45
Show Gist options
  • Save mark-rushakoff/6254147 to your computer and use it in GitHub Desktop.
Save mark-rushakoff/6254147 to your computer and use it in GitHub Desktop.
Is there a difference when using `go foo()` vs. `go func() { foo() }()`? (This never finished when I ran it on my MacBook Air.)
package wrapped_func
// Run this benchmark with `go test -bench=.`
import "testing"
func BenchmarkSendItClean(b *testing.B) {
total := b.N
c := make(chan bool)
for i := 0; i < total; i++ {
go sendIt(c)
}
for i := 0; i < total; i++ {
select {
case <-c:
break
}
}
}
func BenchmarkSendItDirty(b *testing.B) {
total := b.N
c := make(chan bool)
for i := 0; i < total; i++ {
go func() { sendIt(c) }()
}
for i := 0; i < total; i++ {
select {
case <-c:
break
}
}
}
func sendIt(c chan bool) {
c <- true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment