DarkEvE
DarkEvE

Reputation: 17

View executed time of bash script in nanoseconds

Currently, the time $0 command within my bash script shows the following similar output

time $0

real    0m0.000s
user    0m0.000s
sys     0m0.000s

but ideally, I would like to see the execution time of the script in nanoseconds. How would this be done? Thanks

Upvotes: 0

Views: 676

Answers (2)

Tomasz Rochumski
Tomasz Rochumski

Reputation: 31

I'm afraid that you won't get reliable measurements with this precision.

Worth reading

Upvotes: 1

DarkEvE
DarkEvE

Reputation: 17

This solution worked

start_time="$(date -u +%N)"
end_time="$(date -u +%N)"
nanotime="$(bc <<<"$end_time-$start_time")"
echo "$nanotime"

Upvotes: 0

Related Questions