title: fast CUDA thrust custom comparison operator
body: <p>I'm evaluating CUDA and currently using Thrust library to sort numbers.</p>
  
  <p>I'd like to create my own comparer for thrust::sort, but it slows down drammatically!
  I created my own <strong>less</strong> implemetation by just copying code from <strong>functional.h</strong>.
  However it seems to be compiled in some other way and works very slowly.</p>
  
  <ol>
  <li>default comparer: thrust::less() - <strong>94</strong>ms</li>
  <li>my own comparer: less() - <strong>906</strong>ms</li>
  </ol>
  
  <p>I'm using Visual Studio 2010. What should I do to get the same performance as at option 1?</p>
  
  <p>Complete code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #include &lt;cuda.h&gt;
  
  #include &lt;thrust/host_vector.h&gt;
  #include &lt;thrust/device_vector.h&gt;
  #include &lt;thrust/generate.h&gt;
  #include &lt;thrust/sort.h&gt;
  
  int myRand()
  {
          static int counter = 0;
          if ( counter++ % 10000 == 0 )
                  srand(time(NULL)+counter);
          return (rand()&lt;&lt;16) | rand();
  }
  
  template&lt;typename T&gt;
  struct less : public thrust::binary_function&lt;T,T,bool&gt;
  {
    __host__ __device__ bool operator()(const T &amp;lhs, const T &amp;rhs) const {
       return lhs &lt; rhs;
    }
  }; 
  
  int main()
  {
      thrust::host_vector&lt;int&gt; h_vec(10 * 1000 * 1000);
      thrust::generate(h_vec.begin(), h_vec.end(), myRand);
  
      thrust::device_vector&lt;int&gt; d_vec = h_vec;
  
      int clc = clock();
      thrust::sort(d_vec.begin(), d_vec.end(), less&lt;int&gt;());
      printf("%dms\n", (clock()-clc) * 1000 / CLOCKS_PER_SEC);
  
      return 0;
  }
  </code></pre>