Last active
August 19, 2016 20:42
-
-
Save ryanuber/4726e6bcf848c41951164e68011a3b2a to your computer and use it in GitHub Desktop.
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 locktest | |
import ( | |
"sync" | |
"testing" | |
) | |
var l sync.Mutex | |
func dLock() { | |
l.Lock() | |
defer l.Unlock() | |
} | |
func lock() { | |
l.Lock() | |
l.Unlock() | |
} | |
func BenchmarkLock(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
lock() | |
} | |
} | |
func BenchmarkDeferLock(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
dLock() | |
} | |
} |
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
PASS | |
BenchmarkLock-4 100000000 20.7 ns/op | |
BenchmarkDeferLock-4 20000000 93.2 ns/op | |
ok _/Users/ryanuber/Desktop 4.055s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment