2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
describe "Process.times" do
|
2018-02-23 03:45:55 +00:00
|
|
|
it "returns a Process::Tms" do
|
|
|
|
Process.times.should be_kind_of(Process::Tms)
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns current cpu times" do
|
|
|
|
t = Process.times
|
2019-11-30 21:26:52 +01:00
|
|
|
user = t.utime
|
2017-05-07 12:04:49 +00:00
|
|
|
|
2019-11-30 21:26:52 +01:00
|
|
|
1 until Process.times.utime > user
|
|
|
|
Process.times.utime.should > user
|
|
|
|
end
|
2017-05-07 12:04:49 +00:00
|
|
|
|
2020-02-08 19:43:27 +09:00
|
|
|
platform_is_not :windows do
|
|
|
|
it "uses getrusage when available to improve precision beyond milliseconds" do
|
|
|
|
max = 10_000
|
|
|
|
has_getrusage = max.times.find do
|
|
|
|
time = Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
|
|
|
|
('%.6f' % time).end_with?('000')
|
|
|
|
end
|
|
|
|
unless has_getrusage
|
|
|
|
skip "getrusage is not supported on this environment"
|
|
|
|
end
|
2020-03-28 14:39:01 +01:00
|
|
|
|
2020-02-08 19:43:27 +09:00
|
|
|
found = (max * 100).times.find do
|
|
|
|
time = Process.times.utime
|
|
|
|
('%.6f' % time).end_with?('000')
|
2019-11-30 21:26:52 +01:00
|
|
|
end
|
2020-02-08 19:43:27 +09:00
|
|
|
|
|
|
|
found.should_not == nil
|
2019-11-30 21:26:52 +01:00
|
|
|
end
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
end
|