Created
August 16, 2013 22:45
-
-
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.)
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 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