Optimizing Conversion : reltime (elapsed seconds) to Hours Minutes Seconds

8 views
Skip to first unread message

Ni Va

unread,
Jan 21, 2020, 2:55:50 PM1/21/20
to vim_use
Hi,

Using reltime to make trace stamping, I would like to know if there is a more optimized and perf way to calculate the conversion.


       let elapsed = <SID>reltimeelapsed()

" 1. Elapsed Time (in many many seconds)
  let time = elapsed[0] + s:tracer.initial_time.totalStartSecs 

" 2. Calculate how many H M S
let H =  printf("%d",time/3600) "float2nr(time/3600.0)
let rest = time - H*3600

let M =  rest/60
let rest = rest - M*60

" 3. Calculate how many H M S
let S =  rest

  let time = printf('%02s:%02s:%02s', H, M, S)
ici...

with 
fun! s:reltimeelapsed() "{{{

    " Method 1
  let elapsed = reltimefloat(reltime(s:tracer.start_reltime))
  let int =  float2nr(elapsed)
  let fractional = strpart(printf('%.3f', elapsed-int), 1, 4)

  " Method 2
  " let int = str2nr(split(diff_str,'\.')[0])
  " let fractional = '.'.split(diff_str,'\.')[1]

  return [int, fractional]

endfunction "}}}



Thank you
Reply all
Reply to author
Forward
0 new messages