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; rv:150.0) Gecko/20100101 Firefox/150.0
Browser:
Firefox 150
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 days ago
Test name
Executions per second
includes
290214.4 Ops/sec
regex
282872.1 Ops/sec
compiled regex
37707244.0 Ops/sec
variable regex
288676.1 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"); }