Last active
June 28, 2016 12:49
Star
You must be signed in to star a gist
time_math2 vs active-support core ext benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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