Skip to content

Commit 760342c

Browse files
committed
check actual timer
1 parent 1ac2aec commit 760342c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/rdoc/rdoc_comment_test.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,56 @@ def test_clock_actual_res
230230
assert_equal("clock_actualtimes", clockres.inspect)
231231
end
232232

233+
%w[
234+
CLOCK_THREAD_CPUTIME_ID CLOCK_PROCESS_CPUTIME_ID
235+
CLOCK_MONOTONIC
236+
].find do |c|
237+
if Process.const_defined?(c)
238+
[c.to_sym, Process.const_get(c)].find do |clk|
239+
begin
240+
Process.clock_gettime(clk)
241+
rescue
242+
# Constants may be defined but not implemented, e.g., mingw.
243+
else
244+
unless Process.clock_getres(clk) < 1.0e-03
245+
next # needs msec precision
246+
end
247+
PERFORMANCE_CLOCK = clk
248+
end
249+
end
250+
end
251+
end
252+
253+
def test_perf_clock
254+
assert_equal('actual PERFORMANCE_CLOCK:', PERFORMANCE_CLOCK)
255+
end
256+
257+
def test_clock_actual_res_sym
258+
clockres = %i[
259+
CLOCK_THREAD_CPUTIME_ID CLOCK_PROCESS_CPUTIME_ID
260+
CLOCK_MONOTONIC
261+
].map do |c|
262+
begin
263+
clk = c
264+
t0 = t = Process.clock_gettime(clk)
265+
cnt = 0
266+
times = [t]
267+
while times.size < 10
268+
t2 = Process.clock_gettime(clk)
269+
if t2 != t
270+
times << t2
271+
t = t2
272+
end
273+
cnt += 1
274+
end
275+
[cnt, times].inspect
276+
rescue => e
277+
e.message
278+
end
279+
end
280+
assert_equal("clock_actualtimes", clockres.inspect)
281+
end
282+
233283
def test_force_encoding
234284
@comment = RDoc::Encoding.change_encoding @comment, Encoding::UTF_8
235285

0 commit comments

Comments
 (0)