Caching g

Benchmark created on


Setup

const itterations = 50;
const pattern = "*://www.youtube.com/watch?v=*";
const testAgainst = "https://www.youtube.com/watch?v=Am_RcQ2W6u0";

Test runner

Ready to run.

Testing in
TestOps/sec
No Caching
for (let i = 0; i < itterations; i++) {
	const regexPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
	const regex = new RegExp(`^${regexPattern}$`);
	regex.test(testAgainst);
}
ready
With Caching
const _map = new Map();

for (let i = 0; i < itterations; i++) {
	if (_map.has(pattern)) _map.get(pattern).test(testAgainst);
	else {
		const regexPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
		const regex = new RegExp(`^${regexPattern}$`);
		_map.set(pattern, regex);
		_map.get(pattern).test(testAgainst);
	}
}
ready

Revisions

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