* process.c (make_clock_result): add :second as a unit for
Process.clock_gettime. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b7cbdcc5fd
commit
2a732947a6
@ -1,3 +1,8 @@
|
|||||||
|
Mon Dec 16 14:01:48 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* process.c (make_clock_result): add :second as a unit for
|
||||||
|
Process.clock_gettime.
|
||||||
|
|
||||||
Mon Dec 16 13:10:54 2013 Koichi Sasada <ko1@atdot.net>
|
Mon Dec 16 13:10:54 2013 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* gc.c: introduce GC.verify_internal_consistency method to verify GC
|
* gc.c: introduce GC.verify_internal_consistency method to verify GC
|
||||||
|
@ -6825,6 +6825,9 @@ make_clock_result(struct timetick *ttp,
|
|||||||
numerators[num_numerators++] = 1000;
|
numerators[num_numerators++] = 1000;
|
||||||
return timetick2integer(ttp, numerators, num_numerators, denominators, num_denominators);
|
return timetick2integer(ttp, numerators, num_numerators, denominators, num_denominators);
|
||||||
}
|
}
|
||||||
|
else if (unit == ID2SYM(rb_intern("second"))) {
|
||||||
|
return timetick2integer(ttp, numerators, num_numerators, denominators, num_denominators);
|
||||||
|
}
|
||||||
else if (unit == ID2SYM(rb_intern("float_microsecond"))) {
|
else if (unit == ID2SYM(rb_intern("float_microsecond"))) {
|
||||||
numerators[num_numerators++] = 1000000;
|
numerators[num_numerators++] = 1000000;
|
||||||
return timetick2dblnum(ttp, numerators, num_numerators, denominators, num_denominators);
|
return timetick2dblnum(ttp, numerators, num_numerators, denominators, num_denominators);
|
||||||
@ -6958,6 +6961,7 @@ get_mach_timebase_info(void)
|
|||||||
* [:float_second] number of seconds as a float (default)
|
* [:float_second] number of seconds as a float (default)
|
||||||
* [:float_millisecond] number of milliseconds as a float
|
* [:float_millisecond] number of milliseconds as a float
|
||||||
* [:float_microsecond] number of microseconds as a float
|
* [:float_microsecond] number of microseconds as a float
|
||||||
|
* [:second] number of seconds as an integer
|
||||||
* [:millisecond] number of milliseconds as an integer
|
* [:millisecond] number of milliseconds as an integer
|
||||||
* [:microsecond] number of microseconds as an integer
|
* [:microsecond] number of microseconds as an integer
|
||||||
* [:nanosecond] number of nanoseconds as an integer
|
* [:nanosecond] number of nanoseconds as an integer
|
||||||
|
@ -1682,6 +1682,29 @@ EOS
|
|||||||
assert_raise(Errno::EINVAL) { Process.clock_gettime(:foo) }
|
assert_raise(Errno::EINVAL) { Process.clock_gettime(:foo) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_clock_gettime_unit
|
||||||
|
t0 = Time.now.to_f
|
||||||
|
[
|
||||||
|
[:nanosecond, 1_000_000_000],
|
||||||
|
[:microsecond, 1_000_000],
|
||||||
|
[:millisecond, 1_000],
|
||||||
|
[:second, 1],
|
||||||
|
[:float_microsecond, 1_000_000.0],
|
||||||
|
[:float_millisecond, 1_000.0],
|
||||||
|
[:float_second, 1.0],
|
||||||
|
[nil, 1.0],
|
||||||
|
[:foo],
|
||||||
|
].each do |unit, num|
|
||||||
|
unless num
|
||||||
|
assert_raise(ArgumentError){ Process.clock_gettime(Process::CLOCK_REALTIME, unit) }
|
||||||
|
next
|
||||||
|
end
|
||||||
|
t1 = Process.clock_gettime(Process::CLOCK_REALTIME, unit)
|
||||||
|
assert_kind_of num.class, t1, [unit, num].inspect
|
||||||
|
assert_in_delta t0, t1/num, 1, [unit, num].inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_clock_gettime_constants
|
def test_clock_gettime_constants
|
||||||
Process.constants.grep(/\ACLOCK_/).each {|n|
|
Process.constants.grep(/\ACLOCK_/).each {|n|
|
||||||
c = Process.const_get(n)
|
c = Process.const_get(n)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user