-
-
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
Add Time.monotonic to return monotonic clock #5108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,9 +117,9 @@ module Benchmark | |
|
||
# Returns the time used to execute the given block. | ||
def measure(label = "") : BM::Tms | ||
t0, r0 = Process.times, Time.now | ||
t0, r0 = Process.times, Time.monotonic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use tms0 = Process.times
elapsed = Time.measure do
yield
end
tms1 = Process.times
BM::Tms.new(tms1.utime - tms0.utime,
tms1.stime - tms0.stime,
tms1.cutime - tms0.cutime,
tms1.cstime - tms0.cstime,
elapsed.total_seconds,
label) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would hold off on unnecessary changes like that, at least in this PR. They don't simplify anything but do cause errors, as you've pointed out elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors only occur if it involves a return value from the block. Here this doesn't matter. I think it should be worth advocating the more idiomatic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This way it's obvious both measurements are related. It also avoids too much refactor for little purpose. |
||
yield | ||
t1, r1 = Process.times, Time.now | ||
t1, r1 = Process.times, Time.monotonic | ||
BM::Tms.new(t1.utime - t0.utime, | ||
t1.stime - t0.stime, | ||
t1.cutime - t0.cutime, | ||
|
@@ -134,8 +134,6 @@ module Benchmark | |
# Benchmark.realtime { "a" * 100_000 } # => 00:00:00.0005840 | ||
# ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this method be removed/deprecated if it's just an alias for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would support either removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. Well but that's out of the scope of this PR ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, either Removing Benchmark altogether is out-of-scope, indeed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem I see is that people looking at |
||
def realtime : Time::Span | ||
r0 = Time.now | ||
yield | ||
Time.now - r0 | ||
Time.measure { yield } | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
lib LibC | ||
struct MachTimebaseInfo | ||
numer : UInt32 | ||
denom : UInt32 | ||
end | ||
|
||
fun mach_timebase_info(info : MachTimebaseInfo*) : LibC::Int | ||
fun mach_absolute_time : UInt64 | ||
end |
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 simplified the spec, so we verify
elapsed
can be compared against aTime::Span
and the value is always positive.