mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
Check the precision of getrusage at runtime
This commit is contained in:
parent
c5529aa5fc
commit
dafbaabc04
@ -17,8 +17,18 @@ describe "Process.times" do
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: The precision of `getrusage` depends on platforms (OpenBSD
|
||||
# seems not supporting under-milliseconds in fact); this example is
|
||||
# very questionable as an example of Ruby, and it just repeats the
|
||||
# guard condition.
|
||||
guard -> do
|
||||
Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
|
||||
1000.times.any? do
|
||||
# If getrusage has precision beyond milliseconds, there will be
|
||||
# very likely at least one non-zero microsecond results when
|
||||
# repeating enough.
|
||||
time = Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
|
||||
not ('%.6f' % time).end_with?('000')
|
||||
end
|
||||
rescue Errno::EINVAL
|
||||
false
|
||||
end do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user