Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Alphanumeric String (regex, charCodeAt, [])
(version: 0)
Check if a string only contains alpha-numeric characters.
Comparing performance of:
Regex vs charCodeAt vs []
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
var string = "isAlphaNumeric091";
Script Preparation code:
var string = "isAlphaNumeric091";
Tests:
Regex
/^[a-z0-9]+$/i.test(string)
charCodeAt
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)
[]
function isAlphaNumeric(str) { for (let i = 0; i < str.length; i++) { const code = str[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>
Run tests (3)
Previous results
Fork
Test case name
Result
Regex
charCodeAt
[]
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser/OS:
Firefox 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Regex
17147212.0 Ops/sec
charCodeAt
11361514.0 Ops/sec
[]
39542964.0 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?