Reputation: 1347
I've seen a lot of blogs where authors discuss throwing together quick benchmark tests, like this Ruby 1.9.0 v Python 2.5.1 that Antonio Cangiano "throws together at 3am."
Is there a simple way to time a script to the millisecond like that that I'm unaware of? Is he probably using built-in functions of OS X or individual libraries? Does Python have a standard lib for this?
How would you do this if you were just going to take the path of least resistance and throw it together at 3am?
Upvotes: 3
Views: 367
Reputation: 11167
for ruby benchmarking try this
require 'benchmark'
Benchmark.realtime do #your code,this end
also try measure which give more detail total system time etc
Benchmark.measure do
end
Upvotes: 1
Reputation: 160551
Ruby has a Benchmark module as part of the standard distribution. It's simple to use. A quick search here on Stack Overflow will turn up a lot of samples of its use that I've done.
Upvotes: 1
Reputation: 81510
If you're after mere benchmarking, and you're not too worried about start-up time, and you want it to be programming language independent and you're on Unix, you'd probably use unix time
:
time ruby -e "1.upto(10000000) {|i| i}"
real 0m2.926s
user 0m1.570s
sys 0m1.350s
Upvotes: 1
Reputation: 159
I don't know how to do this in Ruby, but in Python I do this -
import time
def my_function():
a = time.clock()
//code which you want to benchmark
b = time.clock()
print b-a
Obviously, this is a "throw together at 3am benchmark." No frills.
Upvotes: 1