extra replace vs subgroup

Benchmark created on


Setup

var txt = 'this-is a text string';

Test runner

Ready to run.

Testing in
TestOps/sec
bare and rough
var name = /^(\*?-?[_a-z0-9-]+[_a-z0-9-\s]*[_a-z0-9-]+)\s*:/.exec(txt);
var result = name && name[1].replace(/\s+/g, '-');
ready
with subgroup
var name = /^(\*?-?[_a-z0-9-]+([_a-z0-9-\s]*)[_a-z0-9-]+)\s*:/.exec(txt);
// checks if subgroup has matched, aka. only replace when needed
var result = name && name[2] && name[1].replace(/\s+/g, '-');
ready

Revisions

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