initial
This commit is contained in:
commit
700dcd90b1
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# patterns
|
||||||
|
|
||||||
|
snippet repository. PRs welcome. doesn't need to run/compile, but cool if
|
||||||
|
it does.
|
23
go/timer.go
Normal file
23
go/timer.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user