Created
October 28, 2022 11:48
-
-
Save by-sabbir/23ec63c1ba7f9fcf6c774efd72ddfd00 to your computer and use it in GitHub Desktop.
go defer timeit
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" | |
| ) | |
| var timeit = func() func() { | |
| start := time.Now() | |
| return func() { | |
| fmt.Println("it took: ", time.Since(start)) | |
| } | |
| } | |
| func main() { | |
| a := timeit() | |
| defer a() | |
| var i int8 = 120 | |
| i += 10 | |
| fmt.Println(i) | |
| for i := 0; i < 2; i++ { | |
| time.Sleep(1 * time.Second) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment