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
<script src = "https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js">
</script>
var r, _ = window._, lodash = window.lodash;
var nestedObj = [
{ id: '4', address: { zipCode: 4, streetName: 'Beta'}},
{ id: '3', address: { zipCode: 3, streetName: 'Alpha' } },
{ id: '1', address: { zipCode: 1, streetName: 'Alpha' } },
{ id: '2', address: { zipCode: 2, streetName: 'Alpha' } },
{ id: '5', address: { zipCode: 4, streetName: 'Alpha' } },
];
var objects = [
{ a: 'x', b: 3 },
{ a: 'y', b: 4 },
{ a: 'x', b: 1 },
{ a: 'y', b: 2 },
];
function sortBy( key, cb ) {
if ( !cb ) cb = () => 0;
return ( a, b ) => ( a[key] > b[key] ) ? 1 :
( ( b[key] > a[key] ) ? -1 : cb( a, b ) );
}
function sortByDesc( key, cb ) {
if ( !cb ) cb = () => 0;
return ( b, a ) => ( a[key] > b[key] ) ? 1 :
( ( b[key] > a[key] ) ? -1 : cb( b, a ) );
}
function orderBy( keys, orders ) {
let cb = () => 0;
keys.reverse();
orders.reverse();
for ( const [i, key] of keys.entries() ) {
const order = orders[i];
if ( order == 'asc' )
cb = sortBy( key, cb );
else if ( order == 'desc' )
cb = sortByDesc( key, cb );
else
throw new Error( `Unsupported order "${order}"` );
}
return cb;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Native Orderby |
| ready |
Lodash order By |
| ready |
Lodash OrderBy Nested |
| ready |
Native Nested Orderby |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.