title: Speeding up a strangely slow Rcpp function
body: <p>I want to rewrite an expensive R function using Rcpp. As I am new to this topic I experimented with some very simple stuff. 
  I wrote the following function:</p>
  
  <pre><code>Rcpp::cppFunction('
    std::vector&lt;int&gt; test_C(double a) {
      std::vector&lt;int&gt; indices;
      indices.reserve(2);
      indices.push_back(a);
      indices.push_back(a);
      return (indices);
    }
  ')
  </code></pre>
  
  <p>Now that works all well regarding the result. But it takes 0.1 seconds (which for this task of course is way too much).  Previously I had </p>
  
  <pre><code>Rcpp::cppFunction('
    NumericVector test_C(double a) {
      NumericVector indices(2);
      indices[0] = a;
      indices[1] = a;
      return (indices);
    }
  ')
  </code></pre>
  
  <p>which was equally slow. I am doubting that this is my systems fault. I tried the Rcpp code in the answer of <a href="https://stackoverflow.com/questions/30026836/r-getting-indices-of-elements-in-a-sorted-vector">R: Getting indices of elements in a sorted vector</a> which calculates which[v > a][1] for a numeric vector v (of length 10e7 in my test) and a double a and it worked very very fast.</p>
  
  <p>Any hint what I am doing wrong? </p>