naTrimS

Benchmark created on


Description

trims non alpha characters from start of string

-- loop is faster up to 5 characters

Setup

const str = "** \" hello world";

Test runner

Ready to run.

Testing in
TestOps/sec
regex
return str.replace(/^[^\w0-9]+/, "");
ready
loop
let s = str;
let code = s.charCodeAt(0);
while(
!(code >= 65 && code <= 90)
&& !(code >= 97 && code <= 122)
&& !(code >= 48 && code <= 57)
) {
	s = s.slice(1);
	code = s.charCodeAt(0);
}

return s;
ready

Revisions

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