[R] timing a function
Peter Ehlers
ehlers at ucalgary.ca
Mon May 17 19:24:53 CEST 2010
On 2010-05-17 10:49, Gustave Lefou wrote:
> Dear all,
>
> I have a function f(x).
>> ptm<- proc.time()
>> y=f(x)
>> proc.time() - ptm
>
> works fine for me.
>
> However it is not possible to write
>
>> system.time(y=f(x))
>
> and
>
>> system.time(f(x))
>
> does not store the value of f(x).
>
> Should I prefer the 3 lines with proc.time ?
No. You should be careful in your use of '=' which is only allowed at
top level.
Try
system.time(y <- f(x))
and see ?"=".
-Peter Ehlers
>
> Thank you very much,
> Gustave
>
>
>
> 2010/5/4 Joris Meys<jorismeys at gmail.com>
>
>> ?system.time can help too.
>>
>> On Tue, May 4, 2010 at 11:07 PM, pdb<philb at philbrierley.com> wrote:
>>
>>>
>>> Hi,
>>> I want to time how long a function takes to execute. Any clues on what to
>>> search for to achieve this?
>>>
>>> Thanks in advance.
>>> --
>>> View this message in context:
>>> http://r.789695.n4.nabble.com/timing-a-function-tp2126319p2126319.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Joris Meys
>> Statistical Consultant
>>
>> Ghent University
>> Faculty of Bioscience Engineering
>> Department of Applied mathematics, biometrics and process control
>>
>> Coupure Links 653
>> B-9000 Gent
>>
>> tel : +32 9 264 59 87
>> Joris.Meys at Ugent.be
>> -------------------------------
>> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list