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?
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.
Example: cmd /v:on /c echo ! TIME! & echo "Quoted mycommand" & cmd /v:on /c echo ! TIME! . Simpler: echo %time% & *mycommand* & call echo %^time% .
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With