-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance.ts
More file actions
67 lines (54 loc) · 1.64 KB
/
performance.ts
File metadata and controls
67 lines (54 loc) · 1.64 KB
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
import fs from "node:fs";
import { readFolders } from "./scripts/readFolders.ts";
import { tryImport } from "./scripts/tryImport.ts";
type FunctionEntryType = [string, (str: string) => unknown]
const { txtFile, folders, year } = readFolders();
for (const folder of folders) {
const { p1, p2, ...otherFunctions } = await tryImport(
`${year}/${folder}/puzzle`
);
const inputPath = `./${year}/${folder}/${txtFile}.txt`;
const inputstring = fs.readFileSync(inputPath, { encoding: "utf8" });
const oterhPart1s = Object.entries(otherFunctions).filter(([functionName]) => functionName.includes("1")) as Array<FunctionEntryType>
const oterhPart2s = Object.entries(otherFunctions).filter(([functionName]) => functionName.includes("2")) as Array<FunctionEntryType>
Deno.bench({
name: `${year}/${folder}: Read File`,
fn: () => {
fs.readFileSync(inputPath, { encoding: "utf8" });
},
});
Deno.bench({
name: `${year}/${folder}: Own`,
group: "Part 1",
baseline: true,
fn: () => {
p1(inputstring);
},
});
Deno.bench({
name: `${year}/${folder}: Own`,
group: "Part 2",
baseline: true,
fn: () => {
p2(inputstring);
},
});
oterhPart1s.forEach(([funcName, func]) => {
Deno.bench({
name: `${year}/${folder}: ${funcName}`,
group: "Part 1",
fn: () => {
func(inputstring);
},
});
})
oterhPart2s.forEach(([funcName, func]) => {
Deno.bench({
name: `${year}/${folder}: ${funcName}`,
group: "Part 2",
fn: () => {
func(inputstring);
},
});
})
}