Array.with() vs Array.toSpliced()

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.

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(
  Math.floor(Math.random() * 1_000_000),
  1,
  'foo'
);
ready
with
const v = a.with(
  Math.floor(Math.random() * 1_000_000),
  'foo'
);
ready

Revisions

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