From fc072a07727865b664dbaaad582b20c0d48c904e Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 9 Mar 2017 20:22:02 +0000 Subject: [PATCH] Get milliseconds timestamps without system() calls for tests --- autoload/ale/engine.vim | 6 +++--- autoload/ale/util.vim | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 1ab9c8b2..63362785 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -644,7 +644,7 @@ endfunction " The time taken will be a very rough approximation, and more time may be " permitted than is specified. function! ale#engine#WaitForJobs(deadline) abort - let l:start_time = system('date +%s%3N') + 0 + let l:start_time = ale#util#ClockMilliseconds() if l:start_time == 0 throw 'Failed to read milliseconds from the clock!' @@ -664,7 +664,7 @@ function! ale#engine#WaitForJobs(deadline) abort for l:job in l:job_list if job_status(l:job) ==# 'run' - let l:now = system('date +%s%3N') + 0 + let l:now = ale#util#ClockMilliseconds() if l:now - l:start_time > a:deadline " Stop waiting after a timeout, so we don't wait forever. @@ -697,7 +697,7 @@ function! ale#engine#WaitForJobs(deadline) abort if l:has_new_jobs " We have to wait more. Offset the timeout by the time taken so far. - let l:now = system('date +%s%3N') + 0 + let l:now = ale#util#ClockMilliseconds() let l:new_deadline = a:deadline - (l:now - l:start_time) if l:new_deadline <= 0 diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index bf00051a..600717db 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -134,3 +134,13 @@ function! ale#util#InSandbox() abort return 0 endfunction + +" Get the number of milliseconds since some vague, but consistent, point in +" the past. +" +" This function can be used for timing execution, etc. +" +" The time will be returned as a Number. +function! ale#util#ClockMilliseconds() abort + return float2nr(reltimefloat(reltime()) * 1000) +endfunction