Unix time command for benchmarking

The Unix time command tells you how long a command takes to run. I recently started using a gem called Zeus to preload my Rails environment and used the time command to measure how much faster commands like $ rake db:migrate are when the Rails environment is preloaded:

$ time bundle exec rake db:migrate
real	0m2.270s
user	0m1.756s
sys	0m0.348s

$ time zeus rake db:migrate
real	0m0.423s
user	0m0.146s
sys	0m0.042s

The time man pages ($ man time) say that the time command “writes the total time elapsed, the time consumed by system overhead, and the time used to execute utility to the standard error stream.” The “real” time is how long the command takes from start to finish and is the typical time of interest when benchmarking. “user” and “sys” are measures of CPU time that was spent, so if you run a process in parallel (on multiple CPUs simultaneously), then the CPU time may be greater than the “real” time. This StackOverflow thread has a more detailed description on the difference between real, user, and sys.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s