Number separate (v2)

Revision 2 of this benchmark created on


Setup

const value = '12345678234567';
let out = '';

Teardown

out = '';

Test runner

Ready to run.

Testing in
TestOps/sec
Split reverse
out = value.split('')
      .reverse()
      .join('')
      .match(/.{1,3}/g)
      ?.join(',')
      .split('')
      .reverse()
      .join('');
ready
Character parse
for (let i = 0; i < value.length; i++) {
  const p = value.length - i - 1;
  out = ((i > 0 && i % 3 === 0) ? value.slice(p, p + 1) + ',': value.slice(p, p + 1)) + out;
}
ready
Char walk
let i = value.length % 3;
out = value.slice(0, i);
while (i < value.length) {
  out +=  ',' + value.slice(i, i + 3);
  i += 3;
}
ready

Revisions

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