Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Test sort numbers
Test several function which sort a number
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Browser:
Chrome 151
Operating system:
Windows
Device Platform:
Desktop
Date tested:
yesterday
Test case mine
3.1M/s
Test case 3
2.9M/s
Test case using sort and reverse
2.8M/s
View exact numbers
Test name
Executions per second
✓
Test case mine
3,050,536 Ops/sec
Test case 3
2,906,811 Ops/sec
Test case using sort and reverse
2,775,698 Ops/sec
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ async function globalMeasureThatScriptPrepareFunction() { // This function is optional, feel free to remove it. // await someThing(); }
Tests:
Test case mine
/*When writing async/deferred tests, use `deferred.resolve()` to mark test as done*/ <!--your preparation HTML code goes here--> function descendingOrder(n) { let str = n.toString(); let startDigit = 9; let digitList = {}; for (let charIndex = 0; charIndex < str.length; charIndex++) { let charAtIndex = str[charIndex]; if (!digitList[charAtIndex]) { digitList[charAtIndex] = 0; } digitList[charAtIndex]++; } let result = ''; for (let digit = 9; digit >= 0; digit--) { let digitStr = digit.toString() let digitCount = digitList[digitStr]; if (digitCount && digitCount > 0) { result += digitStr.repeat(digitCount); } } return Number(result); } descendingOrder(1239901873);
Test case using sort and reverse
function descendingOrder(n){ return parseInt(String(n).split('').sort().reverse().join('')) } descendingOrder(1239901873);
Test case 3
function descendingOrder(n){ return +(n + '').split('').sort(function(a,b){ return b - a }).join(''); } descendingOrder(1239901873);