Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RegExp inside vs outside loop
(version: 0)
RegExp inside vs outside loop
Comparing performance of:
Outside, literal vs Inside, literal vs Outside, object vs Inside, object
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const SIZE = 100000; var chars = new Array(SIZE); for (let index = 0; index < SIZE; index++) { chars[index] = String.fromCodePoint( Math.floor( Math.random() * 0x80 ) ); } var newChars = new Array(SIZE);
Tests:
Outside, literal
const regexp = /[\x00-\x1f\x7f]/g; for (const char of chars) { newChars.push(char.replace(regexp, "")); } console.log(newChars);
Inside, literal
for (const char of chars) { newChars.push(char.replace(/[\x00-\x1f\x7f]/g, "")); } console.log(newChars);
Outside, object
const regexp = new RegExp("[\x00-\x1f\x7f]"); for (const char of chars) { newChars.push(char.replace(regexp, "")); } console.log(newChars);
Inside, object
for (const char of chars) { newChars.push(char.replace(new RegExp("[\x00-\x1f\x7f]"), "")); } console.log(newChars);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Outside, literal
Inside, literal
Outside, object
Inside, object
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:
String from Charcode test 4
Alphanumeric String
testquery
alpha-numeric string
regex vs js - not Alphanumeric String
Comments
Confirm delete:
Do you really want to delete benchmark?