commit 700dcd90b192623a3716b96daca1e11883214e66 Author: sneak Date: Tue Sep 29 16:27:16 2020 -0700 initial diff --git a/README.md b/README.md new file mode 100644 index 0000000..af52f5a --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# patterns + +snippet repository. PRs welcome. doesn't need to run/compile, but cool if +it does. diff --git a/go/timer.go b/go/timer.go new file mode 100644 index 0000000..43d7041 --- /dev/null +++ b/go/timer.go @@ -0,0 +1,23 @@ +package main + +// from https://www.youtube.com/watch?v=yeetIgNeIkc&t=1064s + +import ( + "log" + "time" +) + +func main() { + stop := StartTimer("main") + time.Sleep(1 * time.Second) + defer stop() +} + +func StartTimer(name string) func() { + t := time.Now() + log.Println(name, "started") + return func() { + d := time.Now().Sub(t) + log.Println(name, "took", d) + } +}