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 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0
Browser:
Firefox 131
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
includes
192579.2 Ops/sec
regex
182305.6 Ops/sec
compiled regex
34151988.0 Ops/sec
variable regex
186607.9 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"); }