Skip to content

Instantly share code, notes, and snippets.

@solnic
Last active June 28, 2016 12:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save solnic/a7c917b15d953faf79a83f45d77462b2 to your computer and use it in GitHub Desktop.
time_math2 vs active-support core ext benchmark
Warming up --------------------------------------
time math 2.101k i/100ms
active support 1.619k i/100ms
Calculating -------------------------------------
time math 21.870k (± 4.1%) i/s - 109.252k in 5.003726s
active support 16.309k (± 4.8%) i/s - 82.569k in 5.074850s
Comparison:
time math: 21869.9 i/s
active support: 16308.7 i/s - 1.34x slower
require 'time_math'
require 'active_support/all'
require 'benchmark/ips'
time_op = TimeMath().ceil(:week).advance(:hour, 10)
as_op = -> t { t.next_week + 10.hours }
now = Time.now
puts time_op.(now) == as_op.(now)
Benchmark.ips do |x|
x.report('time math') { time_op.(Time.now) }
x.report('active support') { as_op.(Time.now) }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment