Skip to content

Commit

Permalink
Bench snippet for Array.map
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Sep 28, 2022
1 parent b74351e commit 76b1a3a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions bench/snippets/array-map.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// https://github.com/oven-sh/bun/issues/1096
import { bench, run } from "mitata";

for (let i = 0; i < 20; i++) {
var array = new Array(i);
for (let j = 0; j < i; j++) {
array[j] = 1;
}

bench("Array.map x " + i, () => array.map(identity));
}

bench("inline Array.map x 0", () => [].map(identity));
bench("inline Array.map x 1", () => [1].map(identity));
bench("inline Array.map x 2", () => [1, 1].map(identity));
bench("inline Array.map x 3", () => [1, 1, 1].map(identity));
bench("inline Array.map x 4", () => [1, 1, 1, 1].map(identity));
bench("inline Array.map x 5", () => [1, 1, 1, 1, 1].map(identity));
bench("inline Array.map x 6", () => [1, 1, 1, 1, 1, 1].map(identity));
bench("inline Array.map x 7", () => [1, 1, 1, 1, 1, 1, 1].map(identity));
bench("inline Array.map x 8", () => [1, 1, 1, 1, 1, 1, 1, 1].map(identity));
bench("inline Array.map x 9", () => [1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity));
bench("inline Array.map x 10", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 11", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 12", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 13", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 14", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 15", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 16", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 17", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 18", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);
bench("inline Array.map x 19", () =>
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map(identity)
);

await run();

0 comments on commit 76b1a3a

Please sign in to comment.