[R] system.time()

jim holtman jholtman at gmail.com
Sun Apr 27 02:47:35 CEST 2008

The first two numbers will not add up to the third.  The third is the
elapsed time (wall clock) and the first two are CPU time; even though
they have what appears to be the same units (seconds), they can not
really be compared.  If, for example, was script was taking input from
the console, you will get something like this:

> system.time({
+ x <- scan("")
+ })
1: 12345
Read 1 item
   user  system elapsed
   0.00    0.06    7.34

Here it took 7 seconds for me to enter the data, on only 0.06 seconds
of CPU (all system time -- probably the 'read' function).

The differences in your numbers were the CPU is larger than the
elapsed might be due to the resolution of the time since it was a very
short time, or if you are running an a multiprocessor, and the
application can run multithreaded, you will see the same thing happen
-- e.g., if you have 2 CPU and the application could multithread and
it was CPU bound, then in 10 seconds of elapsed time you might see 20
seconds of CPU time being used.


On Sat, Apr 26, 2008 at 8:32 PM, Fernando Saldanha <fsaldan1 at gmail.com> wrote:
> I thought system.time() would return three numbers, the first two
> adding up to the third one. However, this does not hold in my system
> running Windows Vista Home Premium, with an Intel Core 2 Duo
> processor. For example, using the code in the help for system.time()
> (with one zero added), I got:
> > system.time(for(i in 1:100) mad(runif(10000)))
>   user  system elapsed
>   0.27    0.00    0.25
> Is this a problem with my system clock or am I missing something?
> Thanks.
> FS
> ______________________________________________
> 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.

Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

More information about the R-help mailing list