Skip to content

Commit 02e2452

Browse files
committed
Fixed linting issues
1 parent ef69380 commit 02e2452

File tree

9 files changed

+60
-52
lines changed

9 files changed

+60
-52
lines changed

benchmark/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import myBenchmark from "./memory_benchmarks/myBenchmark";
2626
// ...
2727

2828
const memoryBenchmarkInput: (() => void)[] = [
29-
// ...
30-
myBenchmark
29+
// ...
30+
myBenchmark,
3131
];
3232
```
3333

@@ -42,4 +42,4 @@ To avoid crashes in the CI your benchmark should not use more than 500MB of memo
4242

4343
**Running locally**
4444

45-
`npx typescript-to-lua -p tsconfig.53.json && cd dist && lua -- run.lua ../data/benchmark_master_53.json master`
45+
`npx typescript-to-lua -p tsconfig.53.json && cd dist && lua -- run.lua ../data/benchmark_master_53.json master`

benchmark/benchmark_types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ export enum BenchmarkKind {
33
}
44

55
export interface BenchmarkResult {
6-
kind: BenchmarkKind
6+
kind: BenchmarkKind;
77
}
88

99
export interface MemoryBenchmarkResult extends BenchmarkResult {
10-
kind: BenchmarkKind.Memory
10+
kind: BenchmarkKind.Memory;
1111
benchmarkName: string;
12-
preExecMemoryUsage: number,
13-
postExecMemoryUsage: number,
14-
memoryUsedForExec: number,
15-
memoryAfterGC: number,
12+
preExecMemoryUsage: number;
13+
postExecMemoryUsage: number;
14+
memoryUsedForExec: number;
15+
memoryAfterGC: number;
1616
}
1717

1818
export function isMemoryBenchmarkResult(result: BenchmarkResult): result is MemoryBenchmarkResult {
1919
return result.kind == BenchmarkKind.Memory;
20-
}
20+
}

benchmark/memory_benchmark.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { BenchmarkKind, MemoryBenchmarkResult } from "./benchmark_types";
22
import { round, json } from "./util";
33

4-
54
export function runMemoryBenchmark(benchmarkFunction: Function): MemoryBenchmarkResult {
6-
let result: MemoryBenchmarkResult = { kind: BenchmarkKind.Memory, benchmarkName: "NO_NAME", preExecMemoryUsage: 0, postExecMemoryUsage: 0, memoryUsedForExec: 0, memoryAfterGC: 0 };
5+
let result: MemoryBenchmarkResult = {
6+
kind: BenchmarkKind.Memory,
7+
benchmarkName: "NO_NAME",
8+
preExecMemoryUsage: 0,
9+
postExecMemoryUsage: 0,
10+
memoryUsedForExec: 0,
11+
memoryAfterGC: 0,
12+
};
713

8-
collectgarbage('stop')
14+
collectgarbage("stop");
915
result.preExecMemoryUsage = collectgarbage("count");
1016

1117
benchmarkFunction();
1218

1319
result.postExecMemoryUsage = collectgarbage("count");
1420
result.memoryUsedForExec = result.postExecMemoryUsage - result.preExecMemoryUsage;
1521

16-
collectgarbage("restart")
17-
collectgarbage("collect")
22+
collectgarbage("restart");
23+
collectgarbage("collect");
1824

1925
result.memoryAfterGC = collectgarbage("count");
2026

@@ -23,25 +29,36 @@ export function runMemoryBenchmark(benchmarkFunction: Function): MemoryBenchmark
2329
return result;
2430
}
2531

26-
export function compareMemoryBenchmarks(oldResults: MemoryBenchmarkResult[], updatedResults: MemoryBenchmarkResult[]): [string, string] {
32+
export function compareMemoryBenchmarks(
33+
oldResults: MemoryBenchmarkResult[],
34+
updatedResults: MemoryBenchmarkResult[]
35+
): [string, string] {
2736
let comparisonTable = "| name | master (kb) | commit (kb) | change (kb) | change (%) |\n| - | - | - | - | - |\n";
2837

2938
// we group by the new results in case benchmarks have been added
3039
updatedResults.forEach(newResult => {
3140
const masterResult = oldResults.find(r => r.benchmarkName == newResult.benchmarkName);
3241
if (masterResult) {
33-
const percentageChange = newResult.memoryUsedForExec / masterResult.memoryUsedForExec * 100 - 100;
34-
comparisonTable += `| ${newResult.benchmarkName} | ${round(masterResult.memoryUsedForExec, 3)} | ${round(newResult.memoryUsedForExec, 3)} | ${round(newResult.memoryUsedForExec - masterResult.memoryUsedForExec, 3)} | ${round(percentageChange, 2)} |\n`;
42+
const percentageChange = (newResult.memoryUsedForExec / masterResult.memoryUsedForExec) * 100 - 100;
43+
comparisonTable += `| ${newResult.benchmarkName} | ${round(masterResult.memoryUsedForExec, 3)} | ${round(
44+
newResult.memoryUsedForExec,
45+
3
46+
)} | ${round(newResult.memoryUsedForExec - masterResult.memoryUsedForExec, 3)} | ${round(
47+
percentageChange,
48+
2
49+
)} |\n`;
3550
} else {
3651
// No master found => new benchmark
37-
comparisonTable += `| ${newResult.benchmarkName}(new) | / | ${round(newResult.memoryUsedForExec, 3)} | / | / |\n`;
52+
comparisonTable += `| ${newResult.benchmarkName}(new) | / | ${round(
53+
newResult.memoryUsedForExec,
54+
3
55+
)} | / | / |\n`;
3856
}
3957
});
4058

4159
const markdownSummary = `**Memory:**\n${comparisonTable}`;
4260

43-
const markdownText =
44-
`**master:**\n${json.encode(oldResults)}\n**commit:**\n${json.encode(updatedResults)}`;
61+
const markdownText = `**master:**\n${json.encode(oldResults)}\n**commit:**\n${json.encode(updatedResults)}`;
4562

46-
return [markdownSummary, markdownText]
47-
}
63+
return [markdownSummary, markdownText];
64+
}

benchmark/memory_benchmarks/graph_cylce.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function detectCyleBenchmark() {
2121
function detectCycle<T>(graph: Graph<T>): boolean {
2222
const visited: Map<T, boolean> = new Map();
2323

24-
return [...graph.keys()].some((current) => {
24+
return [...graph.keys()].some(current => {
2525
if (!visited.get(current)) {
2626
return _detectCycle(graph, current, visited, undefined);
2727
}
@@ -37,7 +37,7 @@ function _detectCycle<T>(graph: Graph<T>, current: T, visited: Map<T, boolean>,
3737
throw "Err invalid graph format";
3838
}
3939

40-
return neighbours.some((neighbour) => {
40+
return neighbours.some(neighbour => {
4141
if (!visited.get(neighbour)) {
4242
// If an adjacent is not visited, then recur for that adjacent
4343
return _detectCycle(graph, neighbour, visited, current);
@@ -49,4 +49,4 @@ function _detectCycle<T>(graph: Graph<T>, current: T, visited: Map<T, boolean>,
4949
return true;
5050
}
5151
});
52-
}
52+
}

benchmark/run.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ function benchmark() {
1313
// even if there was no previous one
1414

1515
// Memory tests
16-
const memoryBenchmarkInput: (() => void)[] = [
17-
detectCyleBenchmark
18-
];
16+
const memoryBenchmarkInput: (() => void)[] = [detectCyleBenchmark];
1917

2018
const memoryUpdatedResults = memoryBenchmarkInput.map(runMemoryBenchmark);
2119

@@ -38,18 +36,18 @@ function benchmark() {
3836
print(jsonInfo);
3937
} else {
4038
// No master yet, just write the current results to disk and output empty info
41-
print(json.encode({ summary: "new benchmark (no results yet)", text: "" }))
39+
print(json.encode({ summary: "new benchmark (no results yet)", text: "" }));
4240
}
4341

4442
// Only update baseline if we are on master branch
4543
if (arg[1] && string.find(arg[1], "master")[0]) {
46-
const updatedMasterFile = io.open(arg[0], "w+")[0] as LuaFile
44+
const updatedMasterFile = io.open(arg[0], "w+")[0] as LuaFile;
4745
updatedMasterFile.write(json.encode(updatedResults));
4846
}
4947
}
5048
benchmark();
5149

52-
function loadMasterBenchmarkData(): (string | undefined) {
50+
function loadMasterBenchmarkData(): string | undefined {
5351
const masterFileOpen = io.open(arg[0], "rb");
5452

5553
if (masterFileOpen && masterFileOpen[0]) {
@@ -58,8 +56,7 @@ function loadMasterBenchmarkData(): (string | undefined) {
5856
if (_VERSION == "Lua 5.3") {
5957
// @ts-ignore
6058
masterContent = masterFile.read("a");
61-
}
62-
else {
59+
} else {
6360
// JIT
6461
// @ts-ignore
6562
masterContent = masterFile.read("*a");
@@ -71,4 +68,3 @@ function loadMasterBenchmarkData(): (string | undefined) {
7168
}
7269
}
7370
}
74-

benchmark/tsconfig.53.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"types": [
5-
"lua-types/5.3"
6-
]
4+
"types": ["lua-types/5.3"]
75
},
86
"tstl": {
97
"luaTarget": "5.3"
108
}
11-
}
9+
}

benchmark/tsconfig.jit.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"types": [
5-
"lua-types/jit"
6-
]
4+
"types": ["lua-types/jit"]
75
},
86
"tstl": {
97
"luaTarget": "JIT"
108
}
11-
}
9+
}

benchmark/tsconfig.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{
22
"compilerOptions": {
33
"target": "esnext",
4-
"lib": [
5-
"esnext"
6-
],
4+
"lib": ["esnext"],
75
// Dev types are JIT
8-
"types": [
9-
"lua-types/jit"
10-
],
6+
"types": ["lua-types/jit"],
117
"moduleResolution": "node",
128
"strict": true,
139
"outDir": "dist"
1410
}
15-
}
11+
}

benchmark/util.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export function round(num: number, decimalPlaces: number = 0) {
2-
return tonumber(string.format(`%.${decimalPlaces}f`, num))
2+
return tonumber(string.format(`%.${decimalPlaces}f`, num));
33
}
44

5-
export const json: { decode: (this: void, str: string) => {}, encode: (this: void, val: any) => string } = require("json");
5+
export const json: {
6+
decode: (this: void, str: string) => {};
7+
encode: (this: void, val: any) => string;
8+
} = require("json");

0 commit comments

Comments
 (0)