How to determine which code is faster?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/111368/how-do-you-performance-test-javascript-code">How do you performance test JavaScript code?</a>  </p>
</blockquote>



<p>I am currently trying to learn some JavaScript using js-assessment, which can be found here: <a href="https://github.com/rmurphey/js-assessment" rel="nofollow">https://github.com/rmurphey/js-assessment</a>.</p>

<p>I have written the following code, which let's you find duplicates in an array:</p>

<pre><code>function duplicatesInArray(arr) {
    var test;
    var res = [];

    for (var i = 0; arr[i]; i++) {
        test = arr[i];

        for (var j = i + 1 ; arr[j]; j++) {
            if(arr[j] === test) {
            res.push(arr[j]);
            break;
            }
        }
    }

    return res;
}
</code></pre>

<p>Which works fine, but here's an anwser I've found on github (it works too):</p>

<pre><code>function anotherDuplicatesInArray(arr) {
    var seen = {};
    var dupes = [];

    for (var i = 0, len = arr.length; i &lt; len; i++) {
        seen[arr[i]] = seen[arr[i]] ? seen[arr[i]] + 1 : 1;
    }

    for (var item in seen) {
        if (seen.hasOwnProperty(item) &amp;&amp; seen[item] &gt; 1) {
            dupes.push(item);
        }
    }

    return dupes;
}
</code></pre>

<p>My question is: how can I test which code is better?</p>
