Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Regex vs Forloop Performance
-
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Browser:
Firefox 148
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 months ago
Test name
Executions per second
RegEx
3248042.8 Ops/sec
For Loop
4801747.5 Ops/sec
HTML Preparation code:
var string = "passw)odas4gsdfsdf";
Script Preparation code:
var string = "aaaaabbbbbccccddd";
Tests:
RegEx
var s = string.match(/([a-zA-Z])\1*/g)||[]; return s.map(function(itm){ return [itm.charAt(0), itm.length]; });
For Loop
var result = [[string[0], 1]] for(let i = 1; i < string.length; i++) { const char = string[i] const lastChar = result.at(-1) if(char === lastChar[0]){ lastChar[1] = lastChar[1] + 1 } else { result.push([char, 1]) } }