Different syntaxes for string replace

Benchmark created by Pestilence on


Setup

var c = "Lorem ”ipsum” dolor “ sit ” amet, consectetuer adipiscing elit. Aenean “commodo ” “ … … \u2026 ` ` ‘ ’ ‘ ’"

Test runner

Ready to run.

Testing in
TestOps/sec
Multiple variable value assignement
c = c.replace(/\u2026/g, '...');
c = c.replace(/…/g, '...');
c = c.replace(/[\x93\x94\u201c\u201d]/g, '"');
c = c.replace(/“/g, '"');
c = c.replace(/”/g, '"');
c = c.replace(/“/g, '"');
c = c.replace(/”/g, '"');
c = c.replace(/[\x60\x91\x92\u2018\u2019]/g, ''');
c = c.replace(/`/g, ''');
c = c.replace(/‘/g, ''');
c = c.replace(/’/g, ''');
c = c.replace(/‘/g, ''');
c = c.replace(/’/g, ''');

console.log(c);
ready
Chained replace methods on string
c = c.replace(/\u2026/g, '...').replace(/…/g, '...').replace(/[\x93\x94\u201c\u201d]/g, '"').replace(/(“|”|“|”)/g, '"').replace(/[\x60\x91\x92\u2018\u2019]/g, ''').replace(/(`|‘|’|‘|&#8217)/g, ''');

console.log(c);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Pestilence on