ChrisW
ChrisW

Reputation: 5048

Understanding the behaviour of system.time()

I think I must be misunderstanding something about R's system.time() function. If I have the following code in a test.r:

for(i in 1:10)
{
    print(system.time(testFunction()))
}

(where testFunction() is defined elsewhere, but contains some fairly computationally-intensive code), and run the code, but kill the job after the 1st loop, then receive the following output:

> source("test.r")
user  system elapsed
280.388   2.622 288.155
Timing stopped at: 210.891 0.367 211.637

why is the value for 'Timing Stopped' less than the elapsed time for the function?

Upvotes: 2

Views: 2177

Answers (1)

John Colby
John Colby

Reputation: 22588

The timing restarts during the second loop, and since you killed it part way through, it will be less than what you timed for the full first loop.

Upvotes: 2

Related Questions