On Oct 25, 2008, at 1:23 PM, Nils Rüfenacht wrote:

Thanks for your replies.

There's nothing special about my code (I guess), but here it is.


Well, the only special thing about it is that it's pure interpreted code so it cannot take advantage of anything in R. However, I'm surprised about your timings - are you sure you're not throttling the CPU? See the energy savings preferences - it seems as if you're running in a battery saving mode so the CPU is at half its speed. This is what I get:

mini, Intel Code 1.66GHz (so much slower than yours):
   user  system elapsed
 15.321   0.123  15.764

iMac, Intel Core 2 Duo 2.8GHz (a bit faster than yours):
   user  system elapsed
  8.602   0.067   8.708

Given the kind of code, you cannot expect any magic, because it doesn't use memory or multiple cores, so even the most recent, expensive machines won't be much faster. Raw clock speed is what matters here (whether old Pentium or latest Xeon won't matter much ;)). Given the results above, I'd expect your machine to clock somewhere around 10s. I have compared it to other OSes and the results are consistent ...

Cheers,
Simon




indexGenerator <- function(mue,sigma,duration,numOfSimulations,timeStep = 1/252,nameBasis="Index"){

   m   <- mue
   s   <- sigma
   T   <- duration
   dt  <- timeStep
   n   <- numOfSimulations

   # dataMatrix contains n simulations over T+1 years (from 0 to T)
   dataMatrix      <- matrix(1,nrow=n,ncol=T+1)

   YearEndIndex    <- seq(1:T)/dt + 1

   PTIME <- proc.time()
   for(i in 1:n){

       Index_all   <- seq(0,T,by=dt) + 1
       Index_YE    <- seq(1:(T+1))
       time        <- seq(0,T,by=dt)

       ZFZ <- rnorm(length(Index_all)-1,0,1)

       for(t in 2:length(Index_all)){
Index_all[t] <- Index_all[t-1] + m*Index_all[t-1]*dt + s*Index_all[t-1]*sqrt(dt)*ZFZ[t-1]
       }

       print(paste("Simulation",i,"of",n,"done."),quote=FALSE)
       dataMatrix[i,2:(T+1)] <- t(Index_all[YearEndIndex])
   }

   tableName <- "dummy"
   write.table(dataMatrix,tableName,sep = ";")

   print(proc.time()-PTIME)
}


Without running any other program in the background yields (on my Mac)

> indexGenerator(0.08,0.15,30,100)
  user  system elapsed
19.739   0.220  19.961
> indexGenerator(0.08,0.15,30,1000)
  user  system elapsed
197.721   2.138 199.012
>

I figured out that the function can be made faster by rewriting the code but this doesn't answer my question why my MacBook is slower. Here some specifications:

        Modell-Identifizierung: MacBookPro4,1
        Prozessortyp:   Intel Core 2 Duo
        Prozessorgeschwindigkeit:       2.4 GHz
        Anzahl der Prozessoren: 1
        Gesamtzahl der Kerne:   2
        L2-Cache:       3 MB
        Speicher:       2 GB
        Systemversion:  Mac OS X 10.5.5 (9F33)
        Kernel-Version: Darwin 9.5.0

Before I used a Dell Inspirion 510, running on Windows XP with a 1.7 GHz processor and some lousy 512 MB RAM.

The R-version in use is 2.8.o

Cheers,
Nils



Am 25.10.2008 um 16:41 schrieb Simon Urbanek:


On Oct 24, 2008, at 4:07 PM, Nils Rüfenacht wrote:

I recently changed from a 4 year old Dell running on Windows XP to a mew MacBook Pro running on OS X 10.5. I expected to save an amount of runtime when executing my R code now, but I was mistaken.

I didn't figure out what the problem could be! Same code is running about 30% (!) slower now!

Any suggestions?


What about sharing the code with us? There is very little we can say unless you share the code with us as well as the exact machine specs (and compare the same version of R).

Cheers,
Simon






_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Reply via email to