Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to time a vimscript execution?

Tags:

vim

I try to compare two versions of a same vim function. How can I time them and compare?

What I'm looking for is a simple way to benchmark the first version of the function against the second one, with some kind of precise time echo.

Thank you!

like image 418
phi_st Avatar asked Aug 09 '26 14:08

phi_st


1 Answers

Here is a simple demonstration of the use of :help reltime() and :help reltimestr():

function! Foo()
    " do your thing
    for i in range(1,8)
        let @a = i
    endfor
endfunction

" save current time
let start_time = reltime()

" call your function
call Foo()

" echo elapsed time expressed in seconds
echo "elapsed time:" reltimestr(reltime(start_time))

It should output something like:

elapsed time:   0.000165
like image 194
romainl Avatar answered Aug 12 '26 07:08

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!