From: Brian Candler Date: 2011-04-28T17:04:18+09:00 Subject: Re: float precision Joshua S. wrote in post #995421: > Not surprisingly, it's extremely quicker to convert to a string and > match a regular expression. > > user system total real > spf : 1.560000 0.000000 1.560000 ( 1.557252) > *100 : 0.320000 0.000000 0.320000 ( 0.322573) > *.01 : 0.350000 0.000000 0.350000 ( 0.343289) > regex: 0.000000 0.000000 0.000000 ( 0.000019) You should be suspicious of a result which indicates it's 5 orders of magnitude faster. > r.report('regex:') { > f4 = float.to_s.match(/(^-?\d+(\.\d{1,2})?)/)[1].to_f > } Ahem, you forgot the "times.times do...end" loop in the benchmark :-) -- Posted via http://www.ruby-forum.com/.