Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

measure executing time of command line calls

Tags:

ruby

I am writing a Ruby 1.9.2 script for evaluating the execution times of different external command line calls.

I used the ruby Process.system method to execute the command line calls and tried to capture the executing time as follows:

start = Time.now
system("./script1", "argX")

puts "Duration: #{Time.now - start} seconds"

Now I have the problem that the duration doesn't reflect the execution time of the external process but the execution time of the "system" call.

Any idea how I can measure the execution time of the external process?

like image 916
behas Avatar asked Jan 04 '11 08:01

behas


People also ask

How do you calculate script execution time?

To calculate script execution time use clock time rather than the CPU execution time. Knowing clock time before script execution and after script execution will help to know the script execution time. Clock time can get using microtime() function. First use it before starts the script and then at the end of the script.

How do I measure execution time of a command on the Windows command line?

Example: cmd /v:on /c echo ! TIME! & echo "Quoted mycommand" & cmd /v:on /c echo ! TIME! . Simpler: echo %time% & *mycommand* & call echo %^time% .

How do you time how long a command takes in Linux?

the backslash ( \time ) works in bash and maybe some other shells. command time works in most shells. /usr/bin/time should work in all shells. you can change the output of the system time . use -p to get output similar to the shell builtin time .

What is the output of time command?

The time command prints the elapsed time during the execution of a command, time in the system, and execution time of the time command in seconds to standard error. Note: Sleep time is not charged to either system or user time.


1 Answers

Okay. If I understand what you are trying to do, you want to time how long the "./script1" call takes to run?

One thing you might want to do is to use the benchmark library (it's standard).

require 'benchmark'

Benchmark.bm (7) do |x|
  x.report ("script1:") {system("./script1", "argX")}
end

That will generate a report with user and system times, which may be what you want.

like image 103
philosodad Avatar answered Oct 23 '22 00:10

philosodad