diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-16 23:22:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-16 23:22:42 +0000 |
commit | b701946418aa72eb32587acc71b4479e084ae1be (patch) | |
tree | f09b984459b8e5f4a04e9e1211b66515cbf2232f | |
parent | 1ae9fad62d9aded3016a879ecbab0041fea29724 (diff) | |
download | ruby-b701946418aa72eb32587acc71b4479e084ae1be.tar.gz |
mjit.c: measure time more precisely
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | mjit.c | 5 | ||||
-rw-r--r-- | process.c | 14 |
2 files changed, 16 insertions, 3 deletions
@@ -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 @@ -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; |