From b701946418aa72eb32587acc71b4479e084ae1be Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 16 Jun 2018 23:22:42 +0000 Subject: mjit.c: measure time more precisely git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- mjit.c | 5 +++++ process.c | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mjit.c b/mjit.c index 571f616fe6..3b7714306b 100644 --- a/mjit.c +++ b/mjit.c @@ -219,6 +219,10 @@ static char *libruby_pathflag; 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) 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 diff --git a/process.c b/process.c index 9e242a2605..a60c0df16b 100644 --- a/process.c +++ b/process.c @@ -7184,7 +7184,7 @@ make_clock_result(struct timetick *ttp, } #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) 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) #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) #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; -- cgit v1.2.3