String#to_f slower than Rubinius impl
-------------------------------------
Key: JRUBY-5619
URL: http://jira.codehaus.org/browse/JRUBY-5619
Project: JRuby
Issue Type: Improvement
Components: Performance
Affects Versions: JRuby 1.6
Reporter: Charles Oliver Nutter
Rubinius's implementation of String#to_f (which is entirely native) appears to
be faster than our implementation. There's room for improvement, then.
Here's the benchmark, from Rubinius's suite:
{noformat}
require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |x|
int = "5"
float = "5.0"
empty = ""
with_extra_text = "5.0 and some extra characters"
x.report "#to_f with an integer in a string" do |times|
i = 0
while i < times
int.to_f
i += 1
end
end
x.report "#to_f with a float in a string" do |times|
i = 0
while i < times
float.to_f
i += 1
end
end
x.report "#to_f with an empty string" do |times|
i = 0
while i < times
empty.to_f
i += 1
end
end
x.report "#to_f with a float and trailing text" do |times|
i = 0
while i < times
with_extra_text.to_f
i += 1
end
end
end
{noformat}
And the results. We are faster than 1.9 on every one, but slower than Rubinius
on all but the empty string case:
{noformat}
~/projects/rubinius ➔ jruby --server -I benchmark/lib/
benchmark/core/string/bench_to_f.rb
#to_f with an integer in a string
4492873.5 (±10.5%) i/s - 21610008 in 4.926805s
(cycle=19416)
#to_f with a float in a string
4090389.9 (±7.3%) i/s - 20168125 in 4.972809s
(cycle=38125)
#to_f with an empty string
8870004.5 (±4.9%) i/s - 43788240 in 4.949856s
(cycle=47856)
#to_f with a float and trailing text
3242020.7 (±2.9%) i/s - 16122936 in 4.977419s
(cycle=39517)
~/projects/rubinius ➔ ruby1.9 -I benchmark/lib/
benchmark/core/string/bench_to_f.rb
#to_f with an integer in a string
3297930.1 (±11.4%) i/s - 16248152 in 5.002084s
(cycle=51256)
#to_f with a float in a string
3249934.5 (±9.6%) i/s - 16120108 in 5.010589s
(cycle=51013)
#to_f with an empty string
3436553.5 (±9.8%) i/s - 16996986 in 4.997253s
(cycle=51042)
#to_f with a float and trailing text
2663843.9 (±7.0%) i/s - 13292916 in 5.017321s
(cycle=48692)
~/projects/rubinius ➔ bin/rbx -I benchmark/lib/
benchmark/core/string/bench_to_f.rb
#to_f with an integer in a string
5279759.2 (±1.9%) i/s - 26302185 in 4.983932s
(cycle=44961)
#to_f with a float in a string
5025081.5 (±1.2%) i/s - 25065360 in 4.988854s
(cycle=40428)
#to_f with an empty string
5868962.7 (±2.8%) i/s - 29244904 in 4.987846s
(cycle=47864)
#to_f with a float and trailing text
4398309.3 (±19.2%) i/s - 19126856 in 4.984183s
(cycle=46312)
{noformat}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email