Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
slicing regex vs sticky regex
(version: 0)
Comparing performance of:
slice then regex vs sticky regex
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
s = "" for (let i = 0; i < 1500; i++) { s += String.fromCharCode((Math.random() * (127 - 30) + 32) | 0) } FILTER = /\w/ R1 = /^\w\d/ R2 = /\w\d/y
Tests:
slice then regex
let count = 0 for(let i = 0; i < s.length; i++) { if (FILTER.test(s[i])) { let ss = s.slice(i,i+2) if (R1.test(ss)) { count++ } } }
sticky regex
let count = 0 for(let i = 0; i < s.length; i++) { if (FILTER.test(s[i])) { R2.lastIndex = i let m = R2.exec(s) if (m != null) { count++ } } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
slice then regex
sticky regex
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
isInteger vs Regexp
Alphanumeric String
My Slice vs Regex
RegExp inside vs outside loop
Comments
Confirm delete:
Do you really want to delete benchmark?