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 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0
Browser:
Firefox 147
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 months ago
Test name
Executions per second
RegEx
7795428.5 Ops/sec
For Loop
5636550.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]) } }