Languages
[Edit]
EN

Bash - measure command execution time in milliseconds

9 points
Created by:
marc_so
1164

In this short article, we would like to show how in Bash, measure command execution duration in milliseconds.

Quick solution:

t1=$(date +%s%3N); some_command_here; t2=$(date +%s%3N); echo "$((t2-t1)) ms"

 

Practical example

In the below example the command line sleeps 3 seconds (returns sleeping + execution time).

t1=$(date +%s%3N); sleep 3; t2=$(date +%s%3N); echo "$((t2-t1)) ms"

Example output:

3028 ms
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join