Last active
February 22, 2019 09:24
-
-
Save kasari/ec3c07e49aa2c740fdb84f7abbab9e6c 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 main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
timer := func(tag string) func() { | |
start := time.Now() | |
return func() { | |
fmt.Println(tag, time.Now().Sub(start)) | |
} | |
} | |
stop := timer("sleep") | |
// 何かしらの処理 | |
time.Sleep(time.Millisecond * 200) | |
stop() // sleep 200.896547ms | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment