From 01de0ecbd97117cc05afaad2066f06d8ff77d7f5 Mon Sep 17 00:00:00 2001 From: SUZUKI Sosuke Date: Sat, 27 Dec 2025 17:05:57 +0900 Subject: [PATCH] Add simple benchmark for Array.of (#25711) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **before:** ``` $ bun bench/snippets/array-of.js cpu: Apple M4 Max runtime: bun 1.3.5 (arm64-darwin) benchmark time (avg) (min … max) p75 p99 p999 ----------------------------------------------------------------------------- ----------------------------- int: Array.of(1,2,3,4,5) 9.19 ns/iter (8.1 ns … 108 ns) 9.28 ns 13.63 ns 69.44 ns int: Array.of(100 elements) 1'055 ns/iter (94.58 ns … 1'216 ns) 1'108 ns 1'209 ns 1'216 ns double: Array.of(1.1,2.2,3.3,4.4,5.5) 10.34 ns/iter (8.81 ns … 102 ns) 10.17 ns 17.19 ns 73.51 ns double: Array.of(100 elements) 1'073 ns/iter (124 ns … 1'215 ns) 1'136 ns 1'204 ns 1'215 ns object: Array.of(obj x5) 19.19 ns/iter (16.58 ns … 122 ns) 19.06 ns 77.6 ns 85.75 ns object: Array.of(100 elements) 1'340 ns/iter (294 ns … 1'568 ns) 1'465 ns 1'537 ns 1'568 ns ``` **after:** ``` $ ./build/release/bun bench/snippets/array-of.js cpu: Apple M4 Max runtime: bun 1.3.6 (arm64-darwin) benchmark time (avg) (min … max) p75 p99 p999 ----------------------------------------------------------------------------- ----------------------------- int: Array.of(1,2,3,4,5) 2.68 ns/iter (2.14 ns … 92.96 ns) 2.52 ns 3.95 ns 59.73 ns int: Array.of(100 elements) 23.69 ns/iter (18.88 ns … 155 ns) 20.91 ns 83.82 ns 96.66 ns double: Array.of(1.1,2.2,3.3,4.4,5.5) 3.62 ns/iter (2.97 ns … 75.44 ns) 3.46 ns 5.05 ns 65.82 ns double: Array.of(100 elements) 26.96 ns/iter (20.14 ns … 156 ns) 24.45 ns 87.75 ns 96.88 ns object: Array.of(obj x5) 11.82 ns/iter (9.6 ns … 87.38 ns) 11.23 ns 68.99 ns 77.09 ns object: Array.of(100 elements) 236 ns/iter (206 ns … 420 ns) 273 ns 325 ns 386 ns ``` --- bench/snippets/array-of.js | 335 +++++++++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 bench/snippets/array-of.js diff --git a/bench/snippets/array-of.js b/bench/snippets/array-of.js new file mode 100644 index 0000000000..51e0a47bd5 --- /dev/null +++ b/bench/snippets/array-of.js @@ -0,0 +1,335 @@ +import { bench, run } from "../runner.mjs"; + +let sink; + +// Integers +bench("int: Array.of(1,2,3,4,5)", () => { + sink = Array.of(1, 2, 3, 4, 5); +}); + +bench("int: Array.of(100 elements)", () => { + sink = Array.of( + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + ); +}); + +// Doubles +bench("double: Array.of(1.1,2.2,3.3,4.4,5.5)", () => { + sink = Array.of(1.1, 2.2, 3.3, 4.4, 5.5); +}); + +bench("double: Array.of(100 elements)", () => { + sink = Array.of( + 0.1, + 1.1, + 2.1, + 3.1, + 4.1, + 5.1, + 6.1, + 7.1, + 8.1, + 9.1, + 10.1, + 11.1, + 12.1, + 13.1, + 14.1, + 15.1, + 16.1, + 17.1, + 18.1, + 19.1, + 20.1, + 21.1, + 22.1, + 23.1, + 24.1, + 25.1, + 26.1, + 27.1, + 28.1, + 29.1, + 30.1, + 31.1, + 32.1, + 33.1, + 34.1, + 35.1, + 36.1, + 37.1, + 38.1, + 39.1, + 40.1, + 41.1, + 42.1, + 43.1, + 44.1, + 45.1, + 46.1, + 47.1, + 48.1, + 49.1, + 50.1, + 51.1, + 52.1, + 53.1, + 54.1, + 55.1, + 56.1, + 57.1, + 58.1, + 59.1, + 60.1, + 61.1, + 62.1, + 63.1, + 64.1, + 65.1, + 66.1, + 67.1, + 68.1, + 69.1, + 70.1, + 71.1, + 72.1, + 73.1, + 74.1, + 75.1, + 76.1, + 77.1, + 78.1, + 79.1, + 80.1, + 81.1, + 82.1, + 83.1, + 84.1, + 85.1, + 86.1, + 87.1, + 88.1, + 89.1, + 90.1, + 91.1, + 92.1, + 93.1, + 94.1, + 95.1, + 96.1, + 97.1, + 98.1, + 99.1, + ); +}); + +// Objects +bench("object: Array.of(obj x5)", () => { + sink = Array.of({ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }); +}); + +bench("object: Array.of(100 elements)", () => { + sink = Array.of( + { a: 0 }, + { a: 1 }, + { a: 2 }, + { a: 3 }, + { a: 4 }, + { a: 5 }, + { a: 6 }, + { a: 7 }, + { a: 8 }, + { a: 9 }, + { a: 10 }, + { a: 11 }, + { a: 12 }, + { a: 13 }, + { a: 14 }, + { a: 15 }, + { a: 16 }, + { a: 17 }, + { a: 18 }, + { a: 19 }, + { a: 20 }, + { a: 21 }, + { a: 22 }, + { a: 23 }, + { a: 24 }, + { a: 25 }, + { a: 26 }, + { a: 27 }, + { a: 28 }, + { a: 29 }, + { a: 30 }, + { a: 31 }, + { a: 32 }, + { a: 33 }, + { a: 34 }, + { a: 35 }, + { a: 36 }, + { a: 37 }, + { a: 38 }, + { a: 39 }, + { a: 40 }, + { a: 41 }, + { a: 42 }, + { a: 43 }, + { a: 44 }, + { a: 45 }, + { a: 46 }, + { a: 47 }, + { a: 48 }, + { a: 49 }, + { a: 50 }, + { a: 51 }, + { a: 52 }, + { a: 53 }, + { a: 54 }, + { a: 55 }, + { a: 56 }, + { a: 57 }, + { a: 58 }, + { a: 59 }, + { a: 60 }, + { a: 61 }, + { a: 62 }, + { a: 63 }, + { a: 64 }, + { a: 65 }, + { a: 66 }, + { a: 67 }, + { a: 68 }, + { a: 69 }, + { a: 70 }, + { a: 71 }, + { a: 72 }, + { a: 73 }, + { a: 74 }, + { a: 75 }, + { a: 76 }, + { a: 77 }, + { a: 78 }, + { a: 79 }, + { a: 80 }, + { a: 81 }, + { a: 82 }, + { a: 83 }, + { a: 84 }, + { a: 85 }, + { a: 86 }, + { a: 87 }, + { a: 88 }, + { a: 89 }, + { a: 90 }, + { a: 91 }, + { a: 92 }, + { a: 93 }, + { a: 94 }, + { a: 95 }, + { a: 96 }, + { a: 97 }, + { a: 98 }, + { a: 99 }, + ); +}); + +await run();