time a script

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

time a script

Bee-16
I have used reltime() inside a function and it works.

I thought to make a wrapper for the timer, but it only returns the
time to run the line with execute and not the passed function.

function! Time(fu)
  let start = reltime()
  execute a:fu
  echo reltimestr(reltime(start))
endfun

Is there a way to make this work?
-Bill

--
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
Reply | Threaded
Open this post in threaded view
|

Re: time a script

Nikolay Aleksandrovich Pavlov
Reply to message «time a script»,
sent 01:08:39 22 October 2010, Friday
by Bee:

Try looking at :profile command:
    profile start /path/to/profile.log
    profile func *
    " run something
    qa!
Note not to delete functions before exiting vim.
BTW, what exactly were you passing as a:fu? If it is a function reference (or a
string with function name), then you should have used the following function:
    function Time(funcref, ...)
        let start=reltime()
        call call(a:funcref, a:000, {})
        echo reltimestr(reltime(start))
    endfunction

Original message:

> I have used reltime() inside a function and it works.
>
> I thought to make a wrapper for the timer, but it only returns the
> time to run the line with execute and not the passed function.
>
> function! Time(fu)
>   let start = reltime()
>   execute a:fu
>   echo reltimestr(reltime(start))
> endfun
>
> Is there a way to make this work?
> -Bill

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: time a script

Bee-16
On Oct 21, 2:41 pm, ZyX <[hidden email]> wrote:
> Reply to message «time a script»,
> sent 01:08:39 22 October 2010, Friday
> BTW, what exactly were you passing as a:fu? If it is a function reference (or a
> string with function name), then you should have used the following function:
>     function Time(funcref, ...)
>         let start=reltime()
>         call call(a:funcref, a:000, {})
>         echo reltimestr(reltime(start))
>     endfunction

function! RndTest01a(test,bins,times)

call Time(RndTest01a(1, 10, 5000))

The function "RndTest01a" in my Timer(fu) returns values as expected
but only seems to time the execute a:fu. The "RndTest01a" values and
the echo time are not displayed until the test is done, about 11
seconds but shows 0.000138 seconds with the wrapper.

I tried your suggestion "Time(funcref, ...)" with several variations,
but got errors each time, and still only timed the call call...
(~0.000140 seconds).

--
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
Reply | Threaded
Open this post in threaded view
|

Re: time a script

Bee-16
In reply to this post by Nikolay Aleksandrovich Pavlov
On Oct 21, 2:41 pm, ZyX <[hidden email]> wrote:
> BTW, what exactly were you passing as a:fu? If it is a function reference (or a
> string with function name)...

Ah, the word "string" got me thinking and now it works!

  function! Time(fu)
    let start = reltime()
    execute a:fu
    echo reltimestr(reltime(start))
  endfun

:call Time(':call RndTest01a(1, 10, 5000)')

Thank you for the hint.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: time a script

Nikolay Aleksandrovich Pavlov
In reply to this post by Bee-16
Reply to message «Re: time a script»,
sent 02:13:27 22 October 2010, Friday
by Bee:
> function! RndTest01a(test,bins,times)
>
> call Time(RndTest01a(1, 10, 5000))
>
> The function "RndTest01a" in my Timer(fu) returns values as expected
> but only seems to time the execute a:fu. The "RndTest01a" values and
> the echo time are not displayed until the test is done, about 11
> seconds but shows 0.000138 seconds with the wrapper.
In vimscript all arguments are computed before running a function, so you tried
to execute the result of `RndTest01a', not the `RndTest01a' itself. Your second
version (which passes a string `:call ...') has no such error (though `:' is not
required here). My version have the following advantage: it is much simpler to
pass long or even recursive complex data to called function.

> call Time(RndTest01a(1, 10, 5000))
<...>
> I tried your suggestion "Time(funcref, ...)" with several variations,
> but got errors each time, and still only timed the call call...
> (~0.000140 seconds).
In this case you should have used ``Time('RndTest01a', 1, 10, 5000)''.

signature.asc (205 bytes) Download Attachment