Check digits in number (v4)

Revision 4 of this benchmark created on


Description

Check digits in a number is greater than certain threshold

Setup

function countDigitsByLog(num, threshold) {
    return Math.log10(num) > threshold
}

function countDigitsByStr(num, threshold) {
    return parseInt(num, 10).toString().length > threshold
}
function countDigitsByStrOpt(num, threshold) {
    return `${num}`.length > threshold
}

Test runner

Ready to run.

Testing in
TestOps/sec
countDigitsByLog(1234, 3)
countDigitsByLog(1234, 3)
ready
countDigitsByStr(1234, 3)
countDigitsByStr(1234, 3)
ready
countDigitsByStrOpt(1234, 3)
countDigitsByStrOpt(1234, 3)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.