Created
September 10, 2016 23:46
-
-
Save sspencer/4e16c9cba078921623b5902fb7566a34 to your computer and use it in GitHub Desktop.
Time a function
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
// Golang UK Conference 2016 - Mat Ryer - Idiomatic Go Tricks | |
func StartTimer(name String) func() { | |
t := time.Now() | |
log.Println(name, "started") | |
return func() { | |
d := time.Now().Sub(t) | |
log.Println(name, "took", d) | |
} | |
} | |
func FunkyFunc() { | |
stop := StartTimer("FunkyFunc) | |
defer stop() | |
// preceed with actual function | |
time.Sleep(1 * time.Second) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment