Skip to content

Instantly share code, notes, and snippets.

@poy
Last active July 17, 2017 18:09
Show Gist options
  • Save poy/e3a968b31e341dc75679e2c5c39d7737 to your computer and use it in GitHub Desktop.
Save poy/e3a968b31e341dc75679e2c5c39d7737 to your computer and use it in GitHub Desktop.
Prints duration between ns timestamps from stdin
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
var ds []time.Duration
for scanner.Scan() {
i, err := strconv.ParseUint(scanner.Text(), 10, 64)
if err != nil {
log.Panic(err)
}
ds = append(ds, time.Duration(i))
}
if scanner.Err() != nil {
log.Panic(scanner.Err())
}
for i := 1; i < len(ds)-1; i++ {
fmt.Println(ds[i] - ds[i-1])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment