Tuesday, January 21, 2020

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

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

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/162dab1a-e4c2-45d7-9caa-f5f76e4aec82%40googlegroups.com.

No comments: