From: "Joshua S." Date: 2011-04-29T02:37:37+09:00 Subject: Re: float precision Brian Candler wrote in post #995481: > 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 :-) Wow. Yea ... scratch that. user system total real spf : 1.570000 0.000000 1.570000 ( 1.569649) *100 : 0.330000 0.000000 0.330000 ( 0.323864) *.01 : 0.340000 0.000000 0.340000 ( 0.342777) regex: 4.120000 0.010000 4.130000 ( 4.127264) -- Posted via http://www.ruby-forum.com/.