Create a gist now

Instantly share code, notes, and snippets.

Benchmark: different date classes in old and latest rubies.
require "rubygems"
require "benchmark/ips"
require "date"
require "time"
date = [Date.today, Date.today]
datetime = [DateTime.now, DateTime.now]
time = [Time.now, Time.now]
Benchmark.ips do |x|
x.report("date") { date.first < date.last }
x.report("time") { time.first < time.last }
x.report("datetime") { datetime.first < datetime.last }
x.compare!
end
__END__
# ruby-2.2.3 ###################################################################
Calculating -------------------------------------
date 79.764k i/100ms
time 78.427k i/100ms
datetime 79.333k i/100ms
-------------------------------------------------
date 3.043M (± 5.2%) i/s - 15.235M
time 2.661M (± 6.3%) i/s - 13.254M
datetime 3.042M (± 5.2%) i/s - 15.232M
Comparison:
date: 3042626.0 i/s
datetime: 3042083.6 i/s - 1.00x slower
time: 2660795.7 i/s - 1.14x slower
# ruby-1.8.7 ###################################################################
Calculating -------------------------------------
date 18.366k i/100ms
time 32.166k i/100ms
datetime 13.240k i/100ms
-------------------------------------------------
date 310.321k (± 3.7%) i/s - 1.561M
time 928.706k (± 5.0%) i/s - 4.632M
datetime 192.710k (± 3.6%) i/s - 966.520k
Comparison:
time: 928706.0 i/s
date: 310320.6 i/s - 2.99x slower
datetime: 192710.2 i/s - 4.82x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment