R-Sessions 28: Impressive R Speeds

Yesterday, I received my new Apple MacBook. It’s running a Core 2 Duo at 2.4 Ghz and it’s fast. Really fast!

Apparently, it’s very cool to show of the speed of R-Project on your system. Optimized .DLL files help to speed up your R on Windows systems (and possibly other systems as well) with respect to matrix transformations, which has led to enormous speed increases. So, let’s perform a speed-test of our own.

First of all, in the syntax below, the Matrix package is activated, using the require() command. Since we will be creating random data, we set the seed in order to receive the exact same data every time the test is run. This is done with set.seed(). The next line creates a matrix X, which in the last three lines is manipulated in different ways.

To test how long this takes, we enclose that matrix operations in the system.time() function, which clocks the operation.


require(Matrix)
set.seed(123)
X <- Matrix(rnorm(1e6), 1000)
system.time(for(i in 1:25) X%*%X)
system.time(for(i in 1:25) solve(X))
system.time(for(i in 1:10) svd(X))

This results in the following output:


> X <- Matrix(rnorm(1e6), 1000)
> system.time(for(i in 1:25) X%*%X)
user system elapsed
8.306 0.591 5.031
> system.time(for(i in 1:25) solve(X))
user system elapsed
8.933 1.331 6.684
> system.time(for(i in 1:10) svd(X))
user system elapsed
36.989 3.665 33.384

WOW! This is the fastest I've seen in real life, even faster than some of the desktops that I know people currently work with (i.e. my own). I'm however very sure that it is not the fastest possible, not to say compared with how fast future calculations will be.

Additionally, in the near future my MacBook will be configured with 4 Gb RAM, so I'm curious to find out whether or not this will result in an additional speed increase. I expect, however, most benefit from the additional RAM when doing binomial mixed effects models, so of course expect a comparative benchmark on that one as well as soon as the new RAM arrives.

So, in the meantime, you can use this code to do some benchmarks yourself, on various computers. Please post the results here, or discuss them in the R-Sessions Forum.

UPDATE:
I also tested my old Powerbook G4 (1.5 Ghz, 1.25 Gb RAM):

> set.seed(123)
> X <- Matrix(rnorm(1e6), 1000)
> system.time(for(i in 1:25) X%*%X)
user system elapsed
34.661 1.590 47.528
> system.time(for(i in 1:25) solve(X))
user system elapsed
37.184 1.656 51.516
> system.time(for(i in 1:10) svd(X))
user system elapsed
247.694 11.258 331.979

- - -- --- ----- --------

- - -- --- ----- --------
R-Sessions is a collection of manual chapters for R-Project, which are maintained on Curving Normality. All posts are linked to the chapters from the R-Project manual on this site. The manual is free to use, for it is paid by the advertisements, but please refer to it in your work inspired by it. Feedback and topic requests are highly appreciated.
-------- ----- --- -- - -

Latest Comments

  1. Jeff says:

    > set.seed(123)
    > X system.time(for(i in 1:25) X%*%X)
    user system elapsed
    8.196 0.613 5.256
    > system.time(for(i in 1:25) solve(X))
    user system elapsed
    8.568 1.436 6.856
    > system.time(for(i in 1:10) svd(X))
    user system elapsed
    36.042 4.270 55.122

    Hardware Overview:

    Model Name: MacBook Pro
    Model Identifier: MacBookPro4,1
    Processor Name: Intel Core 2 Duo
    Processor Speed: 2.4 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 3 MB
    Memory: 2 GB

  2. Yason says:

    I don’t quite understand why elapsed time is greater than user+system times in the above examples. In the blog entry you’ve linked in the article, it sound more logical to me: elapsed>user+system. The same is in my experiment (below):

    CPU: Intel Core2Duo @ 3.15GHz
    L2 Cache: 6Mb
    RAM: 4Gb (2x2Gb) @ 800MHz
    OS: Windows XP Pro x64
    R: 2.8.1 (with Rblas.dll from Athlon64_SSE3)

    > system.time(for(i in 1:25) X%*%X)
    user system elapsed
    6.97 0.13 7.32
    > system.time(for(i in 1:25) solve(X))
    user system elapsed
    6.97 0.17 7.50
    > system.time(for(i in 1:10) svd(X))
    user system elapsed
    34.39 0.41 36.25

    1. Rense Nieuwenhuis says:

      Hi there, Yason,

      Indeed, I’ve been puzzled by this one as well. But, fear not: your computer does not travel back in time :-)

      Instead, what is represented here, is that your computer has more than a single core, and that apparently some matrix-calculations are distributed over these multiple cores. Thus, in one second of user time, more than a single second-worth of computing time can take place.

  3. Index of the R-Sessions | Curving Normality
    [...] Impressive R Speeds [...]

Leave a Reply