Created
July 25, 2017 15:22
-
-
Save starius/5d0a73abee1b42156001e62d9140d14b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 main | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
const n = 1000000000 | |
var m sync.Mutex | |
func withLambda() { | |
m.Lock() | |
defer func() { m.Unlock() }() | |
} | |
func withoutLambda() { | |
m.Lock() | |
defer m.Unlock() | |
} | |
func main() { | |
t1 := time.Now() | |
for i := 0; i < n; i++ { | |
withLambda() | |
} | |
fmt.Printf("With lambda: %f ns\n", float64(time.Since(t1).Nanoseconds()) / n) | |
// | |
t2 := time.Now() | |
for i := 0; i < n; i++ { | |
withoutLambda() | |
} | |
fmt.Printf("Without lambda: %f ns\n", float64(time.Since(t2).Nanoseconds()) / n) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment