From ripley at stats.ox.ac.uk  Tue Aug 29 21:29:33 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 29 Aug 2006 20:29:33 +0100 (BST)
Subject: [Rd] Speed of runif() on different Operating Systems
In-Reply-To: <44F2FC78.3040106@mx.uni-saarland.de>
References: <44F2FC78.3040106@mx.uni-saarland.de>
Message-ID: <Pine.LNX.4.64.0608281535580.652@gannet.stats.ox.ac.uk>

No one else seems to have responded to this.

Please see `Writing R Extensions' for how to time things in R.

For things like this, the fine details of how well the compiler keeps the 
pipelines and cache filled are important, as is the cache size and 
memory speed.  Using

system.time(for (i in 1:500) ttt <- runif(1000000))

your Linux time looks slow, indeed slower than the only 32-bit Linux box I 
have left (a 2GHz 512Kb cache Xeon) and 2.5x slower than a 64-bit R on an 
2.2GHz Opteron (which is doing a lot of other work and so only giving 
about 30% of one of its processors to R: the elapsed time was much 
longer).

The binary distribution of R for Windows is compiled with -O3: for some 
tasks it makes a lot of difference and this might just be one.

However, what can you usefully do in R with 5e8 random uniforms in 
anything like a minute, let alone the aggregate time this list will spend 
reading your question?  If it matters to you, investigate the code your 
compiler creates.  (The ATLAS developers report very poor performance on 
certain Pentiums for certain versions of gcc4.)

On Mon, 28 Aug 2006, Martin Becker wrote:

> Dear list,
> 
> I have noticed surprisingly big performance differences of runif() 
> between Windows XP and (Debian) linux on similar CPUs (Pentium D 3.0GHz 
> (WinXP)/3.2GHz (Linux)) and I wonder if there is a simple explanation 
> for the difference.
> On a linux system (with a slightly better CPU and 1GB more RAM), 
> execution of runif() seems to consume about 80% more CPU time than on a 
> Windows XP system.
> On a Xeon 2.7GHz (Debian) linux I have checked, that using the .deb - 
> i386 - Version of R instead of a self-build i686 - version has no 
> noticeable effect on speed.
> Measuring CPU time with Rprof() instead of Sys.time()-differences yields 
> similar results.

You are not measuring CPU time at all with Sys.time.


> Any hint is appreciated, please let me know, if the given information on 
> system/OS or the R output below is not sufficient.
> 
> Regards,
> 
>   Martin Becker
> 
> ------------------------ R - Output  below ------------------------
> 
> Windows XP: (Pentium D, 3.0 GHz)
> 
>  > version
>                _                        
> platform       i386-pc-mingw32          
> arch           i386                     
> os             mingw32                  
> system         i386, mingw32            
> status                                  
> major          2                        
> minor          3.1                      
> year           2006                     
> month          06                       
> day            01                       
> svn rev        38247                    
> language       R                        
> version.string Version 2.3.1 (2006-06-01)
>  > RNGkind()
> [1] "Mersenne-Twister" "Inversion"      
>  > t1<-Sys.time();for (i in 1:500) ttt<-runif(1000000);print(Sys.time()-t1);
> Time difference of 57.969 secs
>  >
> 
> Debian Linux: (Pentium D, 3.2GHz)
> 
>  > version
>                _                        
> platform       i686-pc-linux-gnu        
> arch           i686                     
> os             linux-gnu                
> system         i686, linux-gnu          
> status                                  
> major          2                        
> minor          3.1                      
> year           2006                     
> month          06                       
> day            01                       
> svn rev        38247                    
> language       R                        
> version.string Version 2.3.1 (2006-06-01)
>  > RNGkind()
> [1] "Mersenne-Twister" "Inversion"      
>  > t1<-Sys.time();for (i in 1:500) 
> ttt<-runif(1000000);print(Sys.time()-t1);    
> Time difference of 1.752916 mins
>  >
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




[Rd] Speed of runif() on different Operating Systems
Prof Brian Ripley