staticx
staticx

Reputation: 1281

Linux time command with high precision

I was wondering if there is any linux command (like time or /usr/bin/time) that provides the execution time of one command with high precision in nanoseconds

Upvotes: 6

Views: 7217

Answers (2)

Kuchara
Kuchara

Reputation: 715

I was unable to find any ready-to-use tool, and wrote myself:

$ cat precision-time
#!/bin/bash
start="$(date +'%s.%N')"
$@
echo "$(date +"%s.%N - ${start}" | bc)" >&2

Usage:

$ ./precision-time sleep 1
1.002805151

Upvotes: 2

Jonathan Wakely
Jonathan Wakely

Reputation: 171373

strace -c will count system time in microseconds

strace -ttt will show time of day (with microseconds) for each line of output.

Getting a total time in nanoseconds is probably not useful, because the jitter due to forking and process startup will be orders of magnitude larger than a nanosecond anyway.

Upvotes: 4

Related Questions