0

Trying to set up a benchmark in R, I run a large set of different inputs on a .Call() and measure (=median of 100 replicates) the elapsed time with:

  1. system.time()
  2. microbenchmark()
  3. checking proc.time() before and after the function call.

Confirmingly, results from 1 - 3 are quite comparable.

However, I noted that the time for running this function deviates around integers of milliseconds for all three approaches (Windows 7). Notably, I have another implementation of the benchmark, all written in R and using extensive R-internal (and thus C-coded) functions. The speed is only slightly slower, BUT - using 1 - 3 - can seemingly be pinpointed down to the nanosecond-level.

Question: Why do results deviate at the ms-level for .Call() but not for the latter implementation?

Andrie
  • 176,377
  • 47
  • 447
  • 496
blosloos
  • 21
  • 3
  • Without seeing any actual code, all we can do is guess. My guess is garbage collection. – Joshua Ulrich Sep 18 '14 at 12:30
  • Thank You, Joshua. Unfortunately, it is lengthy code in both cases. Case 1: .Call() in isopattern(...) of package enviPat. Case 2: ecipex(...) of package ecipex. In any case, garbage collection should affect both cases for e.g. system.time(). I have disabled it and run it seperately in all of the above (1)-(3) ... the observation of timing deviating around the ms-level for Case 1 but not Case 2 persists. – blosloos Sep 18 '14 at 13:10
  • 1
    'I have disabled it'. Can garbage collection be disabled? Maybe you mean something else? Do you register your native routines (to avoid repeated need to discover the C function)? Why not simplify (to the point where it can be easily added to the post) your code to illustrate precisely your question, thereby helping to isolate the likely explanation. – Martin Morgan Sep 18 '14 at 13:44
  • I disabled the gc inside system.time() and run it seperately before it. But you are right, Martin, I have not disabled it in my R session, which would be strange. The code is quite long in both cases and I will check if I can provide shorter examples. – blosloos Sep 18 '14 at 13:49

0 Answers0