Array Set Difference

JavaScript performance comparison

Revision 5 of this test case created by

Preparation code

<script src="https://fireboltjs.com/firebolt.min.js"></script>
<script src="https://underscorejs.org/underscore-min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var array = [1,2,3,4,5,6,7,8,9,0],
    sub1 = [1,7,8,4],
    sub2 = [7,3,0];
</script>
    

Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Firebolt
array.diff(sub1);
array.diff(sub1, sub2);
pending…
Underscore
_.difference(array, sub1);
_.difference(array, sub1, sub2);
pending…
jQuery
$(array).not(sub1);
$(array).not(sub1).not(sub2);
pending…
jQuery.grep
jQuery.grep(array, function(i) {
  return jQuery.inArray(i, sub1) === -1;
});
jQuery.grep(array, function(i) {
  return jQuery.inArray(i, sub1) === -1 && jQuery.inArray(i, sub2) === -1;
});
pending…
Native JS
array.filter(function(x) {
  return sub1.indexOf(x) < 0
});
array.filter(function(x) {
  return (sub1.indexOf(x) < 0 && sub2.indexOf(x) < 0)
});
pending…

Compare results of other browsers

Revisions

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

0 Comments