Thanks. I should not try adjusting code after some hours of proofreading. Making that change gave a suitable time difference.
Best, JN On 13-11-03 03:46 PM, Henrik Bengtsson wrote: > tfor <- cmpfun(tfor) > twhile <- cmpfun(twhile) > > /Henrik > > > On Sun, Nov 3, 2013 at 11:55 AM, Prof J C Nash (U30A) <nas...@uottawa.ca> > wrote: >> My bad to not give details. I'm comparing (though not quite directly) to >> results in the posting >> http://rwiki.sciviews.org/doku.php?id=tips:rqcasestudy. >> >> What prompted the query was a write up of "for" versus "while" loops, >> where there was a speedup using compiler for one of these. I had the >> example in a knitr file, and when I was reviewing the text before >> sending it to an editor, I realized the timings no longer supported the >> text. They were, as I recall, developed in R 2.15.2, and I just looked >> through my VMs with different OS's to see if there is one with that >> still extant, but except for a real Win7 case I have been too "good" and >> updated to at least 3.0.1, where I'm getting no advantage. The Win7 case >> is R 2.15.1, and there the compiler actually went slower on one run of >> the code below. That may be due to antivirus running -- had not booted >> that partition for quite a while. >> >> Here is the for-while test code: >> >> # forwhiletime.R >> library(microbenchmark) >> require(compiler) >> >> tfor <- function(n){ >> for (i in 1:n) { >> xx<-exp(sin(cos(as.double(i)))) >> } >> xx >> } >> >> twhile <- function(n){ >> i<-0 >> while (i<n) { >> i<-i+1 >> xx<-exp(sin(cos(as.double(i)))) >> } >> xx >> } >> n<-10000 >> >> timfor<-microbenchmark(tfor(n)) >> timwhile<-microbenchmark(twhile(n)) >> timfor >> timwhile >> cmpfun(tfor) >> cmpfun(twhile) >> timforc<-microbenchmark(tfor(n)) >> timwhilec<-microbenchmark(twhile(n)) >> timforc >> timwhilec >> looptimes<-data.frame(timfor$time, timforc$time, timwhile$time, >> timwhilec$time) >> colMeans(looptimes) >> >> >> Actually, I'm not greatly axious about all this. Mainly I want to make >> sure that I get whatever advice is to be rendered so it is correct. >> >> Best, >> >> JN >> >> >> On 13-11-03 02:22 PM, Duncan Murdoch wrote: >>> On 13-11-03 2:15 PM, Prof J C Nash (U30A) wrote: >>>> I had a bunch of examples of byte code compiles in something I was >>>> writing. Changed to 3.0.2 and the advantage of compiler disappears. I've >>>> looked in the NEWS file but do not see anything that suggests that the >>>> compile is now built-in. Possibly I've just happened on a bunch of >>>> examples where it does not help, but experiences of a year ago do not >>>> seem to remain valid now. Just wondering if my experience was consistent >>>> with what is expected now in 3.0.2. >>> >>> Post some details, please. Are the times in 3.0.2 like the times in >>> 3.0.1 with or without compiling? Or were you comparing to some other >>> version? >>> >>> Duncan Murdoch >>> >>> >>> >> >> ______________________________________________ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel