Skip to content

anonymous /gist:4440875
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
change active_support String#to_date
require 'benchmark'
class String
def old_to_date
unless blank?
date_values = ::Date._parse(self, false).values_at(:year, :mon, :mday)
::Date.new(*date_values)
end
end
def new_to_date
::Date.parse(self, false) unless blank?
end
def blank?
false
end
end
date = '1/2/3'
Benchmark.bm do |x|
x.report('old') { 100000.times { date.old_to_date }}
x.report('new') { 100000.times { date.new_to_date }}
end
=> results
user system total real
old 0.950000 0.000000 0.950000 ( 0.952705)
new 0.940000 0.000000 0.940000 ( 0.945149)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.