ts-japi
Version:
A highly-modular (typescript-friendly)-framework agnostic library for serializing data to the JSON:API specification
51 lines (43 loc) • 1.06 kB
text/typescript
import Benchmark from "benchmark";
const suite = new Benchmark.Suite();
const a: any = new Map();
a.set("test", "test");
const b: any = {};
b.test = "test";
const length = 100; // user defined length
const array: number[] = [];
const map = new Map();
for (let i = 0; i < length; i++) {
array.push(i);
map.set(i, 0);
}
const _tobepushed = [1, 2, 3];
// add tests
suite
.add("Array#ForOf", async () => {
const g = [];
for (const test of array) {
g.push(test);
}
})
.add("Array#index", async () => {
const g = [];
for (let i = 0, len = array.length; i < len; i++) {
g.push(array[i]);
}
})
.add("Array#indexWithTemp", async () => {
const g = [];
for (let i = 0, temp = array[i]; i < array.length; temp = array[++i]) {
g.push(temp);
}
})
// add listeners
.on("cycle", (event: any) => {
console.log(String(event.target));
})
.on("complete", function (this: any) {
console.log(`Fastest is ${this.filter("fastest").map("name")}`);
})
// run async
.run({ async: true });