-
-
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
Replace inappropriate uses of Time.now
#7155
Conversation
The time value is converted to Unix time anyway, so there is no point in assigning a time zone.
It will be transmitted as UTC time anyway, so there is no point in assigning a time zone.
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.
I think having to put everything inside a block hurts readability. Isn't there a similar way to do it without a block?
@asterite Sure, the method body of start = Time.monotonic
do_stuff
elapsed = Time.monotonic - start This would be closer to the previous usage of I'd prefer to use |
@asterite really? |
samples/red_black_tree.cr
Outdated
res = yield | ||
elapsed = Time.measure do | ||
print "#{name}: " | ||
res = nil |
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.
This line is not needed.
This is why I don't like the block form of measure, it forces you to adjust your code (variables inside the block will not be seen outside it).
@ysbaddaden Yes. Because it's a block it forces you to declare some variables outside of it, as in my comment above. The other form is less obtrusive. |
OK, I understand. |
@@ -384,24 +384,26 @@ class RedBlackTreeRunner | |||
end | |||
|
|||
def bench(name, n = 1) | |||
t = Time.now |
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.
The changes to this file are actually already done in #6454, samples/red_black_tree.cr.
For measuring elapsed time,
Time.measure
should be used. In applications, where a time zone won't be used anyway, it's better to useTime.utc_now
instead ofTime.now
to avoid loading a time zone which can be expensive (loading from disk) when it is completely unnecessary.