posva / pretty-hrtime.sh

:clock3: Pretty High Resolution Time in shell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pretty-hrtime.sh Circle CI

Simple shell function to display precise elapsed time.

Usage

ptime [-v|--verbose] [-l|--long] seconds [nanoseconds]

Examples

# Simple example displaying elapsed time using perl
$ start=$(perl -e 'use Time::HiRes qw( gettimeofday ); my ($a, $b) = gettimeofday; $ts = $a; $tn = $b * 1000; print "$ts $tn";')
$ seconds=$(echo "$start" | cut -d ' ' -f 1) 
$ nanoseconds=$(echo "$start" | cut -d ' ' -f 2) 
$ elapsed=$(perl -e 'use Time::HiRes qw( gettimeofday ); my ($a, $b) = gettimeofday; $ts = $a - '"$seconds"'; $tn = $b * 1000 - '"$nanoseconds"'; print "$ts $tn";')
$ ptime $(echo "$elapsed")
6.39 s

$ ptime 37 310000000
37 s

$ ptime 0 3010
3.01 μs

$ ptime --long 3 30000000
3 s 30 ms

$ ptime -l 61 111111111
1 m 1 s 111 ms 111 μs 111 ns

$ ptime -v 1
1 second

Projects using pretty-hrtime.sh

About

:clock3: Pretty High Resolution Time in shell


Languages

Language:Shell 100.0%