replace test

Benchmark created by James on


Setup

var a = "£9897.13";
  var regEx = /\£$/
  const data = [{},{test: '"£9897.13"'}];

Test runner

Ready to run.

Testing in
TestOps/sec
substr
x = (a.substr(0,1) === '£') ? a.substr(1, a.length) : a
ready
regex replace
x = a.replace(/\£$/, '');
ready
precompiled regex replace
x = a.replace(regEx, '');
ready
replace
x = a.replace('£', '');
ready
option 2
const row = (data[1]['test'].substr(0, 1) === '£') ? data[1]['test'].substr(1, data[1]['test'].length) : data[1]['test'];
ready
option 1
const value = data[1]['test'];
const row = (value.substr(0, 1) === '£') ? value.substr(1, value.length) : value;
ready

Revisions

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