I'm trying to measure the execution time of a process that I call via the command line (i.e., I want to find out how long it takes to for the process to finish). Is there any command that I can add to the command calling the process that will achieve this?

share|improve this question

migrated from stackoverflow.com Jul 17 '11 at 12:35

This question came from our site for professional and enthusiast programmers.

Add time before the command you want to measure.

The output will look like:

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

Explanation on real, user and sys (from man time):

  • real: Elapsed real (wall clock) time used by the process, in seconds.
  • user: Total number of CPU-seconds that the process used directly (in user mode), in seconds.
  • sys: Total number of CPU-seconds used by the system on behalf of the process (in kernel mode), in seconds.
share|improve this answer
1  
@ninjalj, can you provide more information on what the real, user, and sys times are that this command returns? – Christopher Kyle Horton Jul 17 '11 at 20:22
2  
@JacobVlijm This answer isn't that elaborate. :) You could edit in your comment and make it so. – muru Feb 13 '15 at 16:43
    
Note that you may need sudo apt-get install time if you are using a shell where time is not a builtin. – poolie Oct 26 '16 at 16:45

For a line-by-line delta measurement, try gnonom.

It is a command line utility, a bit like moreutils's ts, to prepend timestamp information to the standard output of another command. Useful for long-running processes where you'd like a historical record of what's taking so long.

Piping anything to gnomon will prepend a timestamp to each line, indicating how long that line was the last line in the buffer--that is, how long it took the next line to appear. By default, gnomon will display the seconds elapsed between each line, but that is configurable.

gnomon demo

share|improve this answer
    
This is pretty slick. – Nathan Arthur Sep 8 '16 at 21:53
    
(typo in link, fortunately URL ok). You can install it with sudo npm i gnomon -g if you have npm. Not sure how well it does against "progress" lines using '\r' (staying on the same line): in that case I'd like it counting it all as one long line, not separate ones. – Tomasz Gandor Jun 14 '17 at 21:42

You can use time:

time ls -R
share|improve this answer
date +"%T" && cp -r ./file  /destination/folder/here && date +"%T"

Running this command in the terminal will give you the total time for coping a file

share|improve this answer

Occasionally I find myself needing a stopwatch to count how long it takes for an action like my app booting, in which case many of the solutions here are not useful.

For this I like to use sw.

sw

Install

wget -q -O - http://git.io/sinister | sh -s -- -u https://raw.githubusercontent.com/coryfklein/sw/master/sw

Usage

sw
 - start a stopwatch from 0, save start time in ~/.sw
sw [-r|--resume]
 - start a stopwatch from the last saved start time (or current time if no last saved start time exists)
 - "-r" stands for --resume
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.