Differenze di velocità tra Ruby 1.8 e Ruby 1.9
Posted by Dibi Store Fri, 07 Dec 2007 08:57:00 GMT
Visto chè tra un pò uscirà la nuova versione di ruby (la 1.9), ho pensato che sarebbe interessante pubblicare alcuni test che ho fatto per vedere la differenza di velocità nell' interpretazione tra le due versioni. Gli esperimenti sono stati fatti con pezzetti di codice usati comunemente, siete liberi di postare nei commenti anche i vostri esperimenti, che poi potranno essere integrati nel post.
####################
def hash
{"Key1" => "val1", "Key2" => "val2", :key3 => 'val3'}
end
def read_hash
string = ""
hash.each {|k,v| string << "#{k} is #{v}\n" }
end
ruby 1.8
user system total real
first 9.720000 0.010000 9.730000 ( 9.725511)
ruby 1.9
user system total real
first 11.190000 0.020000 11.210000 ( 11.198272)
####################
def string_with_scan
"Questo è un test semplice di scansione".scan(/./) { |x| x }
end
ruby 1.8
user system total real
first 6.500000 0.010000 6.510000 ( 6.505941)
ruby 1.9
user system total real
first 5.850000 0.010000 5.860000 ( 5.868308)
####################
def mega_sum
( 78 * 15 ) / 34 * 23 - (34 * 567)
end
ruby 1.8
user system total real
first 0.910000 0.000000 0.910000 ( 0.915802)
ruby 1.9
user system total real
first 0.310000 0.000000 0.310000 ( 0.327869)
####################
def with_tr
"àòèùàòèùàòèàìììì".tr('àèìòù','aeiou')
end
ruby 1.8
user system total real
first 1.580000 0.000000 1.580000 ( 1.589578)
ruby 1.9
user system total real
first 1.810000 0.010000 1.820000 ( 1.819424)
Considerazioni finali
Sicuramente questo post verrà aggiornato, magari integrando qualche regular expression come test, e altri metodi usati frequentemente
A mio parere ruby è migliorato molto per quanto riguarda la gestione dei numeri, i calcoli e family, ma ha perso qualcosina nelle operazioni con le stringhe, sperò che con la release definitiva prevista prima di natale ci sia qualche miglioramento in questo senso, ma comunque resta il fatto che sono stati fatti importantissimi miglioramenti che gioveranno di sicuro a questo fantastico linguaggio.

