jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase .
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2 Can be accessed at:
https://jsperf.app/negative-modulo/2 underscore.js reject vs native (v11) Revision 11 of this benchmark created by Patrik Affentranger on September 27, 2015 Description Underscore.js has a reject
function which excludes list items that match a criterion. This is to explore whether there's a significant performance difference between this function and a native implementation.
Preparation HTML <script src ="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js" > </script >
Setup window .contacts = [];
var contact;
function getRandomInt (min, max ) {
return Math .floor (Math .random () * (max - min + 1 )) + min;
}
for (var i = 0 ; i < 5000 ; i++) {
contact = {};
contact.firstName = 'firstName' + getRandomInt (1 , 500 );
contact.lastName = 'lastName' + getRandomInt (1 , 500 );
contact.city = ["Boulder" , "Denver" , "Denver" , "Golden" ][getRandomInt (0 , 3 )];
contact.state = "CO" ;
contacts.push (contact);
}
var boulder = window .boulder = window .boulder || {};
Test runner Ready to run.
Run Quick Run Testing in Test Ops/sec filter boulder['filter' ] = _.filter (contacts, function (contact ) {
return contact.city === 'Boulder' ;
});
ready
reject boulder['reject' ] = _.reject (contacts, function (contact ) {
return contact.city !== 'Boulder' ;
});
ready
filter-negated function negate (fn ) {
return function ( ) {
return !fn.apply (this , arguments );
};
}
boulder['filter-negated' ] = _.filter (contacts, negate (function (contact ) {
return contact.city !== 'Boulder' ;
}));
ready
native-code function native_reject (contacts ) {
results = [];
for (var i = 0 ; i < contacts.length ; i++) {
if (contacts[i].city !== 'Boulder' ) results.push (contact);
}
return results;
}
boulder['native-code' ] = native_reject (contacts);
ready
native-filter function native_filter (contacts ) {
results = [];
newIndex = -1 ;
for (var i = 0 ; i < contacts.length ; i++) {
if (contacts[i].city !== 'Boulder' ) {
++newIndex;
results[newIndex] = contact;
}
}
return results;
}
boulder['native-code' ] = native_filter (contacts);
ready
Revisions You can edit these tests or add more tests to this page by appending /edit to the URL.
Revision 1 : published by Ben Atkin on March 18, 2012 Revision 2 : published on August 3, 2012 Revision 3 : published on November 1, 2012 Revision 4 : published on September 2, 2013 Revision 5 : published on March 12, 2014 Revision 6 : published on June 5, 2014 Revision 7 : published by Kevin Attfield on August 25, 2014 Revision 8 : published by Hugo Campos on August 25, 2014 Revision 9 : published by Ryan Witt on October 15, 2014 Revision 11 : published by Patrik Affentranger on September 27, 2015 Revision 12 : published by Patrik Affentranger on September 27, 2015 Revision 14 : published by Mike Huc. on October 26, 2015 Revision 15 : published on January 5, 2016 Revision 16 : published on February 16, 2016 Revision 19 : published on March 10, 2016