Skip to content

Commit

Permalink
[DOC] State the precision of Process.times as platform-defined
Browse files Browse the repository at this point in the history
Remove the bad example that can lead to misunderstanding as if this
precision is defined in Ruby.
  • Loading branch information
nobu committed Oct 3, 2023
1 parent 8be9138 commit 457971f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
1 change: 1 addition & 0 deletions process.c
Expand Up @@ -7836,6 +7836,7 @@ get_clk_tck(void)
* Process.times
* # => #<struct Process::Tms utime=55.122118, stime=35.533068, cutime=0.0, cstime=0.002846>
*
* The precision is platform-defined.
*/

VALUE
Expand Down
27 changes: 0 additions & 27 deletions spec/ruby/core/process/times_spec.rb
Expand Up @@ -16,31 +16,4 @@
Process.times.utime.should > user
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
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, :nanosecond)
not (time % 1_000_000) == 0
end
rescue Errno::EINVAL
false
end do
it "uses getrusage when available to improve precision beyond milliseconds" do
max = 10_000

found = (max * 100).times.find do
time = Process.times.utime
!('%.6f' % time).end_with?('000')
end

found.should_not == nil
end
end
end

0 comments on commit 457971f

Please sign in to comment.