title: JQuery grep(...) VS native JavaScript filter(...) function performance
body: <p>I measured the execution times of those two functions:</p>
  
  <ul>
  <li>jQuery <a href="http://api.jquery.com/jQuery.grep/" rel="nofollow noreferrer">grep</a> function</li>
  <li>Native JavaScript <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter" rel="nofollow noreferrer">filter</a> function</li>
  </ul>
  
  <p>The execution of following methods have been measured using Chrome Profiles tool:</p>
  
  <pre><code>// jQuery GREP function
  function alternative1(words, wordToTest) {
    return $.grep(words, function(word) {
      return wordToTest.indexOf(word) != -1;                    
    });
  }
  
  // Native javascript FILTER function        
  function alternative2(words, wordToTest) {
    return words.filter(function(word) {
      return wordToTest.indexOf(word) != -1;                    
    });
  }
  </code></pre>
  
  <p>Array of <code>words</code> was constructed of 1 million randomly generated strings. Each method was run 20 times. On my surprise <code>jQuery</code> grep function was faster.</p>
  
  <p>Execution times (20 executions):</p>
  
  <ul>
  <li>jQuery <a href="http://api.jquery.com/jQuery.grep/" rel="nofollow noreferrer">grep</a> function <strong>26,31s</strong></li>
  <li>Native JavaScript <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter" rel="nofollow noreferrer">filter</a> function <strong>34,66s</strong></li>
  </ul>
  
  <p>You can repeate measurings on this <a href="http://jsfiddle.net/hfhRC/17/" rel="nofollow noreferrer">jsFidle</a> - it will take some time to execute so be patient.</p>
  
  <p>Is there any explanation why jQuery <a href="http://api.jquery.com/jQuery.grep/" rel="nofollow noreferrer">grep</a> function is faster then <strong>native</strong> JavaScript <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter" rel="nofollow noreferrer">filter</a> function?</p>
  
  <p>PS: This questions was inspired by this <a href="https://stackoverflow.com/a/14012721/617996">answer</a>.</p>