slice() regex vs manually

Benchmark created on


Setup

let acc1 = "";
let acc2 = "";

const regex = /[\w]+/y;

Test runner

Ready to run.

Testing in
TestOps/sec
Test1
for(let i = 0; i < 1000; ++i) {
	let str = ` ${i}`;
	let j = 1;
	let char = str.codePointAt(j);
	while( char >= 97 && char <= 122 || char >= 65 && char <= 90 || char >= 48 && char <= 57 || char === '_' )
	    char = str.codePointAt(++j);
	acc1 += str.slice(1,j);
}
ready
Test2
for(let i = 0; i < 1000; ++i) {
	let str = ` ${i}`;
	regex.lastIndex = 1;
	acc2 += regex.exec(str);
}
ready

Revisions

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