[R] Vectorizing integrate()

Prof J C Nash (U30A) nashjc at uottawa.ca
Fri Dec 7 20:29:16 CET 2012


I found mixed (and not always easy to predict) results from the 
byte-code compiler. It seems necessary to test whether it helps. On some 
calculations, it is definitely worthwhile.

JN


On 12-12-07 01:57 PM, Berend Hasselman wrote:
>
> On 07-12-2012, at 19:37, Spencer Graves wrote:
>
>> On 12/7/2012 9:40 AM, Berend Hasselman wrote:
>>>>
>>>> benchmark(eta1 <- f1(X, B, x, sem1), eta2 <- f2(X, B, x, sem1), eta3 <- f3(X, B, x, sem1),
>>> +           eta4 <- f4(X, B, x, sem1), eta5 <- f5(X, B, x, sem1), eta6 <- f6(X, B, x, sem1),
>>> +           replications=10, columns=c("test","elapsed","relative"))
>>>                         test elapsed relative
>>> 1 eta1 <- f1(X, B, x, sem1)   1.873    1.207
>>> 2 eta2 <- f2(X, B, x, sem1)   1.552    1.000
>>> 3 eta3 <- f3(X, B, x, sem1)   1.807    1.164
>>> 4 eta4 <- f4(X, B, x, sem1)   1.841    1.186
>>> 5 eta5 <- f5(X, B, x, sem1)   1.852    1.193
>>> 6 eta6 <- f6(X, B, x, sem1)   1.601    1.032
>>>
>>> As you can see using the compiler package is beneficial speedwise.
>>> f2 and f6, both the the result of using the compiler package, are the quickest.
>>> It's quite likely that more can be eked out of this.
>>
>>
>>       So the compiler (f2, f4, f6) provided a slight improvement over f1 and f3 but not f2, and in any event, the improvement was not great.
>
> I don't understand the "but not f2".
> And I don't understand the conclusion for (f2,f4,f6). f4 is a compiled version of f3 and is slower than its non compiled version.
> f2 and f6 are the quickest compiled versions.
> Indeed the improvement is not earth shattering but it does demonstrate what you can achieve by using the compiler package.
>
> Berend
>




More information about the R-help mailing list