Timing jobs with time

Sometimes, you might want to know how long a job takes to complete. You can do so using the time command, which times jobs according to the built-in UNIX timer. As Code Listing 9.9shows, all you have to do is enter time followed by the job you want to time.

To time a job using time:

  • time script

    At the shell prompt, type time, followed by the complete job command. After the command finishes, the system will tell you how long it took, as shown in Code Listing 9.9.

To compare job times with time:

1.
time ls

At the shell prompt, type time followed by a job (here, ls).

2.
time nice -n 19 ls

Then, type time followed by another job. In this example, we're comparing a regular ls command to a nice ls command. As Code Listing 9.9 shows, the elapsed time for the nice ls command was considerably longer than the regular ls command.

Tip

Keep in mind that the time a job takes to run may vary according to the system's current load or capacity. For example, a job might take less time to run at 2 A.M., when few people are using the UNIX system, compared to 2 P.M., when many more people are using the system.


Tip

Different systems produce slightly different time outputs. On some systems, you'll get real (clock) time, user time, and system time. Real time is how many seconds on the clock elapsed while the program was running, while user and system time both refer to different measures of how long it took the system to run the job. On other systems, you might get a ton of garbage, as shown in Code Listing 9.10, but the gist of the information is the same.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.175.180