Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
String matching - Regex stripping vs Concatenation of strings
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Regex stripping match
4.1 Ops/sec
Concatenate match with string template
6.8 Ops/sec
Concatenate match with plus
6.8 Ops/sec
HTML Preparation code:
<div></div>
Script Preparation code:
window.stripHtmlSuffix = function(input) { return input.replace(/\.html$/, ''); } window.dataWithHTML = []; window.dataWithOutHTML = []; const possibleChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const TOTAL_STRINGS = 1000; function getRandomInt(max) { return Math.floor(Math.random() * max); } function makeRandomString(len) { var text = ""; for (var i = 0; i < len; i++) { text += possibleChars.charAt(getRandomInt(possibleChars.length)); } return text; } for(let i=0;i<TOTAL_STRINGS;i++) { window.dataWithHTML.push( `${makeRandomString(100 + getRandomInt(150))}.html` ); window.dataWithOutHTML.push( makeRandomString(100 + getRandomInt(150)) ); }
Tests:
Regex strip match
let counter = 0; for(let i = 0;i < window.dataWithOutHTML.length; i++) { let dataWithOutHTML = window.dataWithOutHTML[i]; for(let j = 0;j < window.dataWithHTML.length; j++) { let dataWithHTML = window.dataWithHTML[j]; if (dataWithOutHTML === window.stripHtmlSuffix(dataWithHTML)) { counter++; } } }
Concatenate match string template
let counter = 0; for(let i = 0;i < window.dataWithOutHTML.length; i++) { let dataWithOutHTML = window.dataWithOutHTML[i]; for(let j = 0;j < window.dataWithHTML.length; j++) { let dataWithHTML = window.dataWithHTML[j]; if (dataWithHTML === `${dataWithOutHTML}.html`) { counter++; } } }
Concatenate match with plus
let counter = 0; for(let i = 0;i < window.dataWithOutHTML.length; i++) { let dataWithOutHTML = window.dataWithOutHTML[i]; for(let j = 0;j < window.dataWithHTML.length; j++) { let dataWithHTML = window.dataWithHTML[j]; if (dataWithHTML === (dataWithOutHTML + '.html')) { counter++; } } }