Skip to content

Commit

Permalink
Merge pull request rubinius#1019 from dudleyf/bench-date-parse
Browse files Browse the repository at this point in the history
Add Date.parse benchmark.
  • Loading branch information
burningTyger committed Jun 15, 2011
2 parents 9e322ac + 1c841fe commit 4149f51
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions benchmark/core/date/bench_parse.rb
@@ -0,0 +1,62 @@
require 'benchmark'
require 'benchmark/ips'
require 'date'

Benchmark.ips do |x|
iso_8601_date_only_locale_neutral = "2011-03-08"
iso_8601_date_only_modified = "2011-Mar-08"
rfc2822_date = "08 Mar 11"

format_c = "Fri Jan 02 2004"
format_d = "Fri, 02 Jan 2004"
format_e = "2011/03/08"

x.report "parse '#{iso_8601_date_only_locale_neutral}'" do |times|
i = 0
while i < times
Date.parse(iso_8601_date_only_locale_neutral)
i += 1
end
end

x.report "parse '#{iso_8601_date_only_modified}'" do |times|
i = 0
while i < times
Date.parse(iso_8601_date_only_modified)
i += 1
end
end

x.report "parse '#{rfc2822_date}'" do |times|
i = 0
while i < times
Date.parse(rfc2822_date)
i += 1
end
end

x.report "parse '#{format_c}'" do |times|
i = 0
while i < times
Date.parse(format_c)
i += 1
end
end

x.report "parse '#{format_d}'" do |times|
i = 0
while i < times
Date.parse(format_d)
i += 1
end
end

x.report "parse '#{format_e}'" do |times|
i = 0
while i < times
Date.parse(format_e)
i += 1
end
end

end

0 comments on commit 4149f51

Please sign in to comment.