I was wondering if there is the way to get time in milliseconds from shell script on Mac OS.
I need it to time how much certain query runs.
Now I can only get the time in seconds:
Start=`date +%s`
End =`date +%s`
Time=$Start-$End
just use the 'time' command:
time something
something could be a shell, or a command (find, etc)
the "real" time is the total elapsed time you want, and includes milliseconds
You could use the benchmarking-tool hyperfine
(https://github.com/sharkdp/hyperfine).
It is more elaborate than time
, by default runs your command multiple times and gives you mean runtime, deviation, min, and max.
Simple usage
hyperfine your_command
Result looks like this (result of hyperfine 'sleep 0.5'):
bash-3.2$ hyperfine 'sleep 0.5'
Benchmark #1: sleep 0.5
Time (mean ± σ): 505.6 ms ± 1.5 ms [User: 0.8 ms, System: 1.2 ms]
Range (min … max): 503.1 ms … 508.8 ms 10 runs
There is one caveat, the minimum number of runs is 2 (hyperfine -r 2 'your command'
).
Installation
Hyperfine can be installed via Homebrew:
brew install hyperfine
For more info see: https://github.com/sharkdp/hyperfine#on-macos
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With