Last active
November 9, 2019 06:08
-
-
Save shivamMg/252bd2fb0092d42184922a294d41a72e to your computer and use it in GitHub Desktop.
Time a function in Go
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" | |
| "time" | |
| ) | |
| func main() { | |
| work() | |
| } | |
| func work() { | |
| defer timer(time.Now()).stop() | |
| time.Sleep(time.Second) | |
| } | |
| type timer time.Time | |
| func (t timer) stop() { | |
| fmt.Println(time.Since(time.Time(t))) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment