[前][次][番号順一覧][スレッド一覧]

ruby-changes:32151

From: naruse <ko1@a...>
Date: Mon, 16 Dec 2013 14:04:13 +0900 (JST)
Subject: [ruby-changes:32151] naruse:r44230 (trunk): * process.c (make_clock_result): add :second as a unit for

naruse	2013-12-16 14:04:03 +0900 (Mon, 16 Dec 2013)

  New Revision: 44230

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44230

  Log:
    * process.c (make_clock_result): add :second as a unit for
      Process.clock_gettime.

  Modified files:
    trunk/ChangeLog
    trunk/process.c
    trunk/test/ruby/test_process.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44229)
+++ ChangeLog	(revision 44230)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Dec 16 14:01:48 2013  NARUSE, Yui  <naruse@r...>
+
+	* process.c (make_clock_result): add :second as a unit for
+	  Process.clock_gettime.
+
 Mon Dec 16 13:10:54 2013  Koichi Sasada  <ko1@a...>
 
 	* gc.c: introduce GC.verify_internal_consistency method to verify GC
Index: process.c
===================================================================
--- process.c	(revision 44229)
+++ process.c	(revision 44230)
@@ -6825,6 +6825,9 @@ make_clock_result(struct timetick *ttp, https://github.com/ruby/ruby/blob/trunk/process.c#L6825
         numerators[num_numerators++] = 1000;
         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"))) {
         numerators[num_numerators++] = 1000000;
         return timetick2dblnum(ttp, numerators, num_numerators, denominators, num_denominators);
@@ -6958,6 +6961,7 @@ get_mach_timebase_info(void) https://github.com/ruby/ruby/blob/trunk/process.c#L6961
  *  [:float_second] number of seconds as a float (default)
  *  [:float_millisecond] number of milliseconds 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
  *  [:microsecond] number of microseconds as an integer
  *  [:nanosecond] number of nanoseconds as an integer
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 44229)
+++ test/ruby/test_process.rb	(revision 44230)
@@ -1682,6 +1682,29 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1682
     assert_raise(Errno::EINVAL) { Process.clock_gettime(:foo) }
   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
     Process.constants.grep(/\ACLOCK_/).each {|n|
       c = Process.const_get(n)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]