findUnique

JavaScript performance comparison

Test case created

Info

find unique element using array or object key

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var test = [];
    for (var i = 0; i < 100000; i++) {
      test.push(Math.random() * 10000);
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
array
var m = [];
for (var j = 0; j < test.length; j++) {
  if (m.indexOf(test[j])) {
    m.push(test[j]);
  }
}
pending…
object
var n = {};
for (var j = 0; j < test.length; j++) {
  if (n[test[j]]) {
    n[test[j]] = true;
  }
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment