IndexOf (v2)

Revision 2 of this benchmark created on


Setup

let acc1 = 0; // regex
let acc2 = 0; // <=
let acc3 = 0; // with ord() <=
let acc4 = 0; // with ord() <=
let acc5 = 0; // with ord() <=
let acc6 = 0;
let acc7 = 0;
let acc8 = 0;
let acc9 = 0;


const Regex1=(/[^a-zA-Z0-9_]/);
const Regex2=(/[^\w]/);
const Regex3=(/^[\w]+/);
const Regex4=(/[\w]+/y);

Test runner

Ready to run.

Testing in
TestOps/sec
Regex
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	acc1 += str.slice(2).search(Regex1);
}
ready
Manual
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	let j = 2;
	let char = str[j];
	while( char >= 'a' && char <= 'z' || char >= 'A' && char <= 'Z' || char >= '0' && char <= '9' || char === '_' )
	    char = str[++j];
	acc2 += j;
}
ready
Manual with ord
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	let j = 2;
	let char = str.codePointAt(j);
	while( char >= 97 && char <= 122 || char >= 65 && char <= 90 || char >= 48 && char <= 57 || char === '_' )
	    char = str.codePointAt(++j);
	acc3 += j;
}
ready
Manual with ord2
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	let j = 2;
	let char = str.charCodeAt(j);
	while( char >= 97 && char <= 122 || char >= 65 && char <= 90 || char >= 48 && char <= 57 || char === '_' )
	    char = str.charCodeAt(++j);
	acc4 += j;
}
ready
Regex2
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	acc5 += str.slice(2).search(Regex2);
}
ready
Regex3
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	Regex3.exec(str.slice(2));
	acc6 += Regex3.lastIndex;
}
ready
Regex4
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	const reg = /^[\w]+/;
	reg.exec(str.slice(2));
	acc7 += reg.lastIndex;
}
ready
test
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	Regex3.lastIndex = 2;
	Regex3.exec(str);
	acc8 += Regex3.lastIndex;
}
ready
test2
for(let i = 0; i < 1000; ++i) {
	let str = `${i} ${i}`;
	Regex4.lastIndex = 2;
	Regex4.exec(str);
	acc8 += Regex4.lastIndex;
}
ready

Revisions

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