aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-10-03 14:42:47 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-10-03 14:42:47 +0900
commit457971f4e243a76084d06ae840f4218b7a2062a3 (patch)
tree211eeed2351f0091174ddfd17019cc25ca01a771
parent8be9138de2f9c6ce418f43ee55f5e6bce645bc28 (diff)
downloadruby-457971f4e243a76084d06ae840f4218b7a2062a3.tar.gz
[DOC] State the precision of `Process.times` as platform-defined
Remove the bad example that can lead to misunderstanding as if this precision is defined in Ruby.
-rw-r--r--process.c1
-rw-r--r--spec/ruby/core/process/times_spec.rb27
2 files changed, 1 insertions, 27 deletions
diff --git a/process.c b/process.c
index 4f3d72cf68..85f1fca467 100644
--- a/process.c
+++ b/process.c
@@ -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
diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb
index 9e16c36b7a..d3bff2cda9 100644
--- a/spec/ruby/core/process/times_spec.rb
+++ b/spec/ruby/core/process/times_spec.rb
@@ -16,31 +16,4 @@ describe "Process.times" do
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