Last active
July 17, 2017 18:09
-
-
Save poy/e3a968b31e341dc75679e2c5c39d7737 to your computer and use it in GitHub Desktop.
Prints duration between ns timestamps from stdin
This file contains hidden or 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 ( | |
"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