mjit.c: measure time more precisely

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-06-16 23:22:42 +00:00
parent 1ae9fad62d
commit b701946418
2 changed files with 16 additions and 3 deletions

5
mjit.c
View File

@ -219,6 +219,10 @@ static char *libruby_pathflag;
static void remove_file(const char *filename); static void remove_file(const char *filename);
/* Return time in milliseconds as a double. */ /* 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 static double
real_ms_time(void) real_ms_time(void)
{ {
@ -239,6 +243,7 @@ real_ms_time(void)
return tv.tv_usec / 1000.0 + tv.tv_sec * 1000.0; return tv.tv_usec / 1000.0 + tv.tv_sec * 1000.0;
#endif #endif
} }
#endif
/* Make and return copy of STR in the heap. */ /* Make and return copy of STR in the heap. */
#define get_string ruby_strdup #define get_string ruby_strdup

View File

@ -7184,7 +7184,7 @@ make_clock_result(struct timetick *ttp,
} }
#ifdef __APPLE__ #ifdef __APPLE__
static mach_timebase_info_data_t * static const mach_timebase_info_data_t *
get_mach_timebase_info(void) get_mach_timebase_info(void)
{ {
static mach_timebase_info_data_t sTimebaseInfo; static mach_timebase_info_data_t sTimebaseInfo;
@ -7195,6 +7195,14 @@ get_mach_timebase_info(void)
return &sTimebaseInfo; 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 #endif
/* /*
@ -7450,7 +7458,7 @@ rb_clock_gettime(int argc, VALUE *argv)
#ifdef __APPLE__ #ifdef __APPLE__
#define RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC ID2SYM(id_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC) #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) { 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(); uint64_t t = mach_absolute_time();
tt.count = (int32_t)(t % 1000000000); tt.count = (int32_t)(t % 1000000000);
tt.giga_count = 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 #ifdef RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC
if (clk_id == 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.count = 1;
tt.giga_count = 0; tt.giga_count = 0;
numerators[num_numerators++] = info->numer; numerators[num_numerators++] = info->numer;