STLSet vs Underscore

JavaScript performance comparison

Test case created by Ameya

Info

Checking speed of STLSet vs Underscore for inserting duplicate elements

Preparation code

<script src="https://raw.github.com/ameyakarve/STLJS/master/stl.js">
</script>
<script src="https://raw.github.com/bestiejs/lodash/master/lodash.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var intConstructor = function(object) {
        return (typeof(object.key) === "number" && typeof(object.value) === "number");
        };
    var intCompare = function(one, two) {
        if (one.key < two.key) return -1;
        if (one.key > two.key) return 1;
        return 0;
        };
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
STLJS
var intSet = new STLSet(intConstructor, intCompare);
for (var i = 0; i < 10000; i++) {
  intSet.insert(false, {
    key: (i % 600) | 0,
    value: 6
  });
}
intSet.toArray();
pending…
Underscore
var underScoreArray = [];
for (var i = 0; i < 10000; i++) {
  underScoreArray.push({
    key: (i % 600) | 0,
    value: 6
  });
}
_.uniq(underScoreArray);
pending…
Underscore check each step
var underScoreArray = [];
for (var i = 0; i < 10000; i++) {
  if (!(_.contains(underScoreArray, {
    key: (i % 600) | 0,
    value: 6
  }))) underScoreArray.push({
    key: (i % 600) | 0,
    value: 6
  });
}
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