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

ruby-changes:51464

From: nobu <ko1@a...>
Date: Sun, 17 Jun 2018 08:22:48 +0900 (JST)
Subject: [ruby-changes:51464] nobu:r63674 (trunk): mjit.c: measure time more precisely

nobu	2018-06-17 08:22:42 +0900 (Sun, 17 Jun 2018)

  New Revision: 63674

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63674

  Log:
    mjit.c: measure time more precisely

  Modified files:
    trunk/mjit.c
    trunk/process.c
Index: mjit.c
===================================================================
--- mjit.c	(revision 63673)
+++ mjit.c	(revision 63674)
@@ -219,6 +219,10 @@ static char *libruby_pathflag; https://github.com/ruby/ruby/blob/trunk/mjit.c#L219
 static void remove_file(const char *filename);
 
 /* Return time in milliseconds as a double.  */
+#ifdef __APPLE__
+double ruby_real_ms_time(void);
+#define real_ms_time() ruby_real_ms_time()
+#else
 static double
 real_ms_time(void)
 {
@@ -239,6 +243,7 @@ real_ms_time(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L243
     return tv.tv_usec / 1000.0 + tv.tv_sec * 1000.0;
 #endif
 }
+#endif
 
 /* Make and return copy of STR in the heap. */
 #define get_string ruby_strdup
Index: process.c
===================================================================
--- process.c	(revision 63673)
+++ process.c	(revision 63674)
@@ -7184,7 +7184,7 @@ make_clock_result(struct timetick *ttp, https://github.com/ruby/ruby/blob/trunk/process.c#L7184
 }
 
 #ifdef __APPLE__
-static mach_timebase_info_data_t *
+static const mach_timebase_info_data_t *
 get_mach_timebase_info(void)
 {
     static mach_timebase_info_data_t sTimebaseInfo;
@@ -7195,6 +7195,14 @@ get_mach_timebase_info(void) https://github.com/ruby/ruby/blob/trunk/process.c#L7195
 
     return &sTimebaseInfo;
 }
+
+double
+ruby_real_ms_time(void)
+{
+    const mach_timebase_info_data_t *info = get_mach_timebase_info();
+    uint64_t t = mach_absolute_time();
+    return (double)t * info->numer / info->denom / 1e6;
+}
 #endif
 
 /*
@@ -7450,7 +7458,7 @@ rb_clock_gettime(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L7458
 #ifdef __APPLE__
 #define RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC ID2SYM(id_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC)
         if (clk_id == RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC) {
-	    mach_timebase_info_data_t *info = get_mach_timebase_info();
+	    const mach_timebase_info_data_t *info = get_mach_timebase_info();
             uint64_t t = mach_absolute_time();
             tt.count = (int32_t)(t % 1000000000);
             tt.giga_count = t / 1000000000;
@@ -7589,7 +7597,7 @@ rb_clock_getres(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L7597
 
 #ifdef RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC
         if (clk_id == RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC) {
-	    mach_timebase_info_data_t *info = get_mach_timebase_info();
+	    const mach_timebase_info_data_t *info = get_mach_timebase_info();
             tt.count = 1;
             tt.giga_count = 0;
             numerators[num_numerators++] = info->numer;

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

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