-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Time methods #6581
Refactor Time methods #6581
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, sorry to have to ask but do you have any performance benchmarks?
I actually didn't expect much change in This is my benchmark, it's running through the entire date range, so maybe a bit overkill... require "benchmark"
struct Time
Benchmark.ips do |bm|
bm.report "new impl" do
(1..9999).each do |year|
ordinal = 0
(1..12).each do |month|
(1..days_in_month(year, month)).each do |day|
ordinal += 1
Time.absolute_days(year, month, day)
end
end
end
end
bm.report "old impl" do
(1..9999).each do |year|
ordinal = 0
(1..12).each do |month|
(1..days_in_month(year, month)).each do |day|
ordinal += 1
Time.absolute_days_old(year, month, day)
end
end
end
end
end
end |
@straight-shoota 10% is fine |
b97ce42
to
8a1e06e
Compare
The value range is already checked in `leap_year?`
8a1e06e
to
fa4aa63
Compare
This PR refactors
Time.year_month_day_year
andTime.absolute_days
to simplify the code and make it easier to understand.The changes are mostly just formal, but there are a few semantic changes such as storing the value of an expression in a local variable for re-use.