Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Sort with compare inside/outside with try catch
test
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
inside compare
13.5 Ops/sec
outside compare
29.4 Ops/sec
Script Preparation code:
var filteredData = Array.from({length: 1000000}, () => (Math.floor(Math.random() * 100000) === 4) ? null : (Math.random() + 1).toString(36).substring(7)); var sortOrder = 'DESC';
Tests:
inside compare
filteredData.sort((a, b) => { try{ if (sortOrder === 'DESC') { return b.localeCompare(a); } return a.localeCompare(b); } catch (e) { console.log('error for a: ', a, 'and b: ', b) return 0 } });
outside compare
filteredData.sort( sortOrder === 'DESC' ? (a, b) => { try{ return b.localeCompare(a) } catch(e) { console.log('error for a: ', a, 'and b: ', b) return 0 } } : (b, a) => { try { return b.localeCompare(a) } catch(e) { console.log('error for a: ', a, 'and b: ', b) return 0 } } );