Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Reverse a number
Which is the faster way to reverse a number in JS?
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0
Browser:
Firefox 143
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one month ago
Test name
Executions per second
reverseNum numerically
165601.4 Ops/sec
The String way
160650.0 Ops/sec
Tests:
reverseNum numerically
let num = 456 var r = 0; while (num) { r *= 10; r += num % 10; num = Math.floor(num / 10); } console.log(r)
The String way
let num = 456 Number(num.toString().split('').reverse().join('')) console.log(num)