Array.with() vs Array.toSpliced() (v2)

Revision 2 of this benchmark created on


Description

This is to compare the speed of the two array methods: with and toSpliced to see if there is any discernible difference in performance when returning an array with a value replaced. This time we're using fixed index-item numbers.

Setup

const a = new Array(1_000_000)
  .fill(1)
  .map((_v, i) => i);

Test runner

Ready to run.

Testing in
TestOps/sec
toSpliced
const v = a.toSpliced(
  999990,
  1,
  'foo'
);
ready
with
const v = a.with(
  999990,
  'foo'
);
ready

Revisions

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