Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
regex vs compiled regex vs includes
Compares the difference in performance between regex, compiled regex and includes.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser:
Chrome 147
Operating system:
Windows
Device Platform:
Desktop
Date tested:
10 days ago
Test name
Executions per second
includes
390527.9 Ops/sec
regex
366965.7 Ops/sec
compiled regex
28319192.0 Ops/sec
variable regex
361903.0 Ops/sec
Script Preparation code:
// Note that var is used to take advantage of global scope var text = `{"A lot more stuff than what we have before and by a lot more i don't actually mean that much more but it's still more FetchInputEventCrashTimeout":"Watchdog FetchInputEvent were not being fed for 30000 milliseconds.Crash timeout was set to 30000 milliseconds."}` var regex = new RegExp('\bWatchdog'); var regexVar = /\bWatchdog/;
Tests:
includes
const result = text.includes("Watchdog"); if (result){ console.log("something"); }
regex
const result = text.match(/\bWatchdog/); if (result){ console.log("something"); }
compiled regex
// Note, the following is included in the preperation code // var regex = new RegExp('\bWatchdog'); const result = regex.test(text) if (result){ console.log("something"); }
variable regex
const result = regexVar.test(text) if (result){ console.log("something"); }