diff options
Diffstat (limited to 'autoload/xolox/misc/timer.vim')
-rw-r--r-- | autoload/xolox/misc/timer.vim | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/autoload/xolox/misc/timer.vim b/autoload/xolox/misc/timer.vim index 151972d..d7fc32d 100644 --- a/autoload/xolox/misc/timer.vim +++ b/autoload/xolox/misc/timer.vim @@ -1,6 +1,7 @@ -" Vim auto-load script +" Timing of long during operations. +" " Author: Peter Odding <peter@peterodding.com> -" Last Change: March 15, 2011 +" Last Change: May 19, 2013 " URL: http://peterodding.com/code/vim/misc/ if !exists('g:timer_enabled') @@ -13,24 +14,33 @@ endif let s:has_reltime = has('reltime') -" Start a timer. - -function! xolox#misc#timer#start() +function! xolox#misc#timer#start() " {{{1 + " Start a timer. This returns a list which can later be passed to + " `xolox#misc#timer#stop()`. if g:timer_enabled || &verbose >= g:timer_verbosity return s:has_reltime ? reltime() : [localtime()] endif return [] endfunction -" Stop a timer and print the elapsed time (only if the user is interested). - -function! xolox#misc#timer#stop(...) +function! xolox#misc#timer#stop(...) " {{{1 + " Show a formatted debugging message to the user, if the user has enabled + " increased verbosity by setting Vim's ['verbose'] [verbose] option to one + " (1) or higher. + " + " This function has the same argument handling as Vim's [printf()] [printf] + " function with one difference: At the point where you want the elapsed time + " to be embedded, you write `%s` and you pass the list returned by + " `xolox#misc#timer#start()` as an argument. + " + " [verbose]: http://vimdoc.sourceforge.net/htmldoc/options.html#'verbose' + " [printf]: http://vimdoc.sourceforge.net/htmldoc/eval.html#printf() if (g:timer_enabled || &verbose >= g:timer_verbosity) call call('xolox#misc#msg#info', map(copy(a:000), 's:convert_value(v:val)')) endif endfunction -function! s:convert_value(value) +function! s:convert_value(value) " {{{1 if type(a:value) != type([]) return a:value elseif !empty(a:value) @@ -49,7 +59,10 @@ endfunction let s:units = [['day', 60 * 60 * 24], ['hour', 60 * 60], ['minute', 60], ['second', 1]] -function! xolox#misc#timer#format_timespan(ts) +function! xolox#misc#timer#format_timespan(ts) " {{{1 + " Format a time stamp (a string containing a formatted floating point + " number) into a human friendly format, for example 70 seconds is phrased as + " "1 minute and 10 seconds". " Convert timespan to integer. let seconds = a:ts + 0 |