Skip to content

Instantly share code, notes, and snippets.

@iMarv
Created May 30, 2020 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iMarv/28626689223eebe0c9fd1ffccaf8fd94 to your computer and use it in GitHub Desktop.
Save iMarv/28626689223eebe0c9fd1ffccaf8fd94 to your computer and use it in GitHub Desktop.
import { bench, runBenchmarks } from "https://deno.land/std/testing/bench.ts";
bench({
name: "normalArray",
runs: 10000,
func(b): void {
const values = [];
for (let x = 0; x < 100; x++) {
for (let y = 0; y < 100; y++) {
values.push({ a: 1, b: 2 });
}
}
b.start();
for (const v of values) {
}
b.stop();
},
});
bench({
name: "frozenArray",
runs: 10000,
func(b): void {
const values = [];
for (let x = 0; x < 100; x++) {
for (let y = 0; y < 100; y++) {
values.push({ a: 1, b: 2 });
}
}
const frozen = Object.freeze(values);
b.start();
for (const v of frozen) {
}
b.stop();
},
});
runBenchmarks();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment