title: windows version of R package much slower than linux version
body: <p>I'm running ubuntu, 64bit. I have this minimal test package that i made to learn how to do these things (I'm following this <a href="http://www.google.be/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CDUQFjAA&amp;url=http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf&amp;ei=IOvrUOe3G4rL0AWSjoGADA&amp;usg=AFQjCNHmlajNmMov0zsiVa4dw9iyhupiDQ&amp;sig2=CUYtDZA7v60R5PL9JmikOQ&amp;bvm=bv.1357316858,d.d2k&amp;cad=rja" rel="nofollow noreferrer">tutorial</a>, except i also have some c code in the package). </p>
  
  <p>The package build/runs in linux so i set about making it run in windows too.</p>
  
  <p>I followed this <a href="https://stackoverflow.com/a/14212267/189035">answer</a> and used the online windows package builder maintained by Uwe Ligges to get a (working) zip version of my <a href="http://win-builder.r-project.org/AYd113V9vPd4/" rel="nofollow noreferrer">package</a>. </p>
  
  <p>Now, when i install that .zip package on windows (7-64) the small demo code runs slower than the linux version. As in 30 times slower. I doubt the difference is always so large. 
  I'm wondering what i'm doing wrong and how i can fix this gap.</p>
  
  <h1>EDIT:</h1>
  
  <p>this is the source code (it's a minimal working example):</p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  #include &lt;functional&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;math.h&gt;
  #include &lt;time.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sstream&gt;
  #include &lt;vector&gt;
  
  #include &lt;Eigen/Dense&gt;
  #include &lt;Eigen/LU&gt;
  #include &lt;Eigen/SVD&gt;
  
  using namespace std;
  using namespace Eigen;
  using Eigen::MatrixXf;
  using Eigen::VectorXf;
  
  
  float median(VectorXf&amp; x) {
      int n=x.rows();
      int half=(n+1)/2;   
      half--;                 
      float med;
      nth_element(x.data(),x.data()+half,x.data()+x.size());  
      if((n%2)==1){
          med=x(half);
      } else {
          float tmp0=x(half);
          float tmp1=x.segment(half+1,half-1).minCoeff(); 
          med=0.5*(tmp0+tmp1);
      }
      return med;
  }
  VectorXf fx01(MatrixXf&amp; x){
      int p=x.cols();
      int n=x.rows();
      VectorXf Recept(n);
      VectorXf Result(p);
      for(int i=0;i&lt;p;i++){
          Recept=x.col(i);
          Result(i)=median(Recept);
      }
      return Result;
  }
  extern "C"{
      void mse(int* n,int* p,float* x,float* medsout){
          MatrixXf x_cen=Map&lt;MatrixXf&gt;(x,*n,*p);  
          VectorXf MedsOut=fx01(x_cen);
          Map&lt;VectorXf&gt;(medsout,*p)=MedsOut.array();
      }
  }
  </code></pre>
  
  <h1>EDIT2:</h1>
  
  <p>Following cbeleites suggestion i ran the code multiple times. Doing this I found 
  a strange thing: the function's timing are actually the same as linux except when 
  i call <code>apply()</code> before calling my function --I was always comparing the timing 
  of the colwise median my pack computes to the timing of doing <code>apply(X,2,median)</code>-- </p>
  
  <p>Ok, problem solved. For now. Still i'm curious now: why would a good old fashioned 
  call to <code>apply()</code> (on a huge matrix X) wreck things so badly (system.time went from 
  90sec to 3sec)?</p>