Skip to content

Instantly share code, notes, and snippets.

@mcansky
Created May 11, 2012 06:56
Show Gist options
  • Select an option

  • Save mcansky/2658018 to your computer and use it in GitHub Desktop.

Select an option

Save mcansky/2658018 to your computer and use it in GitHub Desktop.
FaP (Fork and Play)
## solve this
#
# max 3 lignes, benche avec Benchmark (http://ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html)
#
# "34,6".to_f -> 34 ; comment faire pour obtenir 34.6 comme un Float/Decimal ?
#
@mcansky

mcansky commented May 11, 2012

Copy link
Copy Markdown
Author
require 'benchmark'

Benchmark.bm do |x|
  x.report { "34,6".gsub(",",".").to_f }
  x.report { "34,6".gsub(/,/,".").to_f }
  x.report { "34,6".tr(",",".").to_f }
end
# output
#  0.000000   0.000000   0.000000 (  0.000086)
#  0.000000   0.000000   0.000000 (  0.000011)
#  0.000000   0.000000   0.000000 (  0.000019)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment