I decided to see how long it would take to iterate through an array of hashes. Below is the code:
pairs = [{name: "firstname", value: "string"},{name: "lastname", value: "string"},{name: "country", value: "string"},{name: "city", value: "string"},{name: "state", value: "string"},{name: "company", value: "string"},{name: "year", value: "string"},{name: "political_affiliation", value: "string"},{name: "social_security_number", value: "string"}] * 1000
blank = {}
start = Time.now
pairs.each do |pair|
blank[pair[:name]] = pair[:value]
end
p Time.now - start
Time is calculated by subtracting the current time after the loop from the current time before the loop.
This was the amount of time the computation took in YARV 2.1.1, according to the math in the code:
0.001962017
Here's how long it took in Rubinius 2.2.6:
0.022598
And jRuby 1.7.12
0.022317
Supposedly Rubinius and jRuby have performance advantages over YARV. Why do they take almost 12 times the amount of time to perform the same basic operation? Is this normal or do I have something improperly configured?
You are benchmarking too tiny times, which are compromised by enviroment loading. In my experience, in order to have reliable benchmarks you have to get timings of at least 10 seconds, in order to mitigate warmup times. Around 10 seconds I expect JRuby to be the most performant, followed by Ruby and Rubinius.
Let's see:
This is the output on my machine (I use fish shell + rbenv, you should write your own script):
As I supposed, JRuby is the fastest with 4.367000, than Ruby with 8.188726 and last Rubinius with 14.193565.