-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbench.ts
61 lines (49 loc) · 1.34 KB
/
bench.ts
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
import { lastItem } from "./mod.ts";
import arrayLast from "https://esm.sh/[email protected]";
const exampleArray = Array.from({ length: 9e7 });
Deno.bench("Last item [lastItem]", { group: "Single Item" }, () => {
lastItem(exampleArray);
});
Deno.bench("Last item [Array.prototype.at]", { group: "Single Item" }, () => {
exampleArray.at(-1);
});
Deno.bench("Last item [arrayLast]", { group: "Single Item" }, () => {
arrayLast(exampleArray);
});
Deno.bench("Last item [Direct Indexing]", { group: "Single Item" }, () => {
exampleArray[exampleArray.length - 1];
});
Deno.bench(
"Last Multiple Items [lastItem]",
{ group: "Multiple Items" },
() => {
lastItem(exampleArray, 10);
},
);
Deno.bench(
"Last Multiple Items [Array.prototype.slice]",
{ group: "Multiple Items" },
() => {
exampleArray.slice(-10);
},
);
Deno.bench(
"Last Multiple Items [arrayLast]",
{ group: "Multiple Items" },
() => {
arrayLast(exampleArray, 10);
},
);
Deno.bench("All Items [lastItem]", { group: "All Items" }, () => {
lastItem(exampleArray, exampleArray.length);
});
Deno.bench("All Items [Array.prototype.slice]", { group: "All Items" }, () => {
exampleArray.slice(-exampleArray.length);
});
Deno.bench(
"All Items [arrayLast]",
{ group: "All Items", ignore: true },
() => {
arrayLast(exampleArray, exampleArray.length);
},
);