From 291ce2c2a453a10f039b737ae8fdb0cde8eec30e Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Mon, 17 Sep 2012 19:12:08 -0700 Subject: [PATCH] more --- README | 18 ++++++++++++++---- src/xx-elapsed.go | 10 ++++++++++ src/xx-epoch.go | 13 +++++++++++++ src/xx-scatter-gather.go | 21 +++++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/xx-elapsed.go create mode 100644 src/xx-epoch.go create mode 100644 src/xx-scatter-gather.go diff --git a/README b/README index fefc15b..0c78ca5 100644 --- a/README +++ b/README @@ -1,8 +1,17 @@ += next +write blog post on Go on Heroku +market blog post on Go on Heroku +proof ebook toolchain + += vision +must-have book for hackers interested in Go +sold at a significant price and producing real revenue +notable example of ebook product and marketing + = values design -curation -excellence -excitement +empathy +creativity = validation private emails @@ -55,7 +64,6 @@ gobyexample.com signups * web app * hipache port * templating -* scatter-gather * ssh * environment variables * dns @@ -71,3 +79,5 @@ gobyexample.com signups * sort-by * errors * compilation +* time +* time duration diff --git a/src/xx-elapsed.go b/src/xx-elapsed.go new file mode 100644 index 0000000..96b52e7 --- /dev/null +++ b/src/xx-elapsed.go @@ -0,0 +1,10 @@ +package main + +import ("time"; "fmt") + +func main() { + start := time.Now() + time.Sleep(3 * time.Second) + finish := time.Now() + fmt.Println(finish.Sub(start)) +} diff --git a/src/xx-epoch.go b/src/xx-epoch.go new file mode 100644 index 0000000..9df4fdc --- /dev/null +++ b/src/xx-epoch.go @@ -0,0 +1,13 @@ +package main + +import ("time"; "fmt") + +func main() { + now := time.Now() + secs := now.Unix() + nanos := now.UnixNano() + millis := nanos / 1000000 + fmt.Println("Seconds since epoch:", secs) + fmt.Println("Millis since epoch:", millis) + fmt.Println("Nanos since epoch:", nanos) +} diff --git a/src/xx-scatter-gather.go b/src/xx-scatter-gather.go new file mode 100644 index 0000000..8a4cb34 --- /dev/null +++ b/src/xx-scatter-gather.go @@ -0,0 +1,21 @@ +package main + +import ("sync"; "time"; "math/rand"; "fmt") + +func main() { + times := new([20]int) + wait := new(sync.WaitGroup) + for i := 0; i < 20; i++ { + n := i + wait.Add(1) + go func() { + opTime := rand.Intn(2000) + time.Sleep(time.Duration(opTime) * time.Millisecond) + fmt.Println(n) + times[n] = opTime + wait.Done() + }() + } + wait.Wait() + fmt.Println(*times) +}