array map vs fill spread

Benchmark created on


Setup

const offset = 10;
const thumbnailWidth = 50;

const keyframes = Array.from(
  { length: 20 },
  (_, i) => i * Math.random(),
);

Test runner

Ready to run.

Testing in
TestOps/sec
map
const arr = [
  offset, 
  ...keyframes.map(() => thumbnailWidth),
];
ready
Array constructor + fill
const arr = [
  offset,
...Array(keyframes.length).fill(thumbnailWidth),
];
ready
Array.from
const arr = [
  offset, 
  ...Array.from(
    { length: 20}, 
    () => thumbnailWidth,
  ),
];
ready

Revisions

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