HTML Preparation code:
AخA
 
1
var string = "isAlphaNumeric2021"
Script Preparation code:
 
var string = "isAlphaNumeric2021"
Tests:
  • Regex

     
    /^[a-z0-9]+$/i.test(string)
  • charCodeAt

    x
     
    function isAlphaNumeric(str) {
        for (let i = 0; i < str.length; i++) {
            let code = str.charCodeAt(i)
            if (!(code > 47 && code < 58) && // numeric (0-9)
                !(code > 64 && code < 91) && // upper alpha (A-Z)
                !(code > 96 && code < 123)) { // lower alpha (a-z)
                return false
            }
        }
        return true
    }
    isAlphaNumeric(string)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Regex
    charCodeAt

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Chrome 95 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Regex 8593835.0 Ops/sec
charCodeAt 8993151.0 Ops/sec