forked from MCJack123/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_benchmark.ts
More file actions
43 lines (36 loc) · 1.24 KB
/
runtime_benchmark.ts
File metadata and controls
43 lines (36 loc) · 1.24 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
import { BenchmarkKind, ComparisonInfo, RuntimeBenchmarkResult } from "./benchmark_types";
import { compareNumericBenchmarks } from "./benchmark_util";
import { json, toFixed } from "./util";
export function runRuntimeBenchmark(benchmarkFunction: () => void): RuntimeBenchmarkResult {
const result: RuntimeBenchmarkResult = {
kind: BenchmarkKind.Runtime,
benchmarkName: "NO_NAME",
time: 0,
};
// normalize times a bit
collectgarbage("collect");
const startTime = os.clock();
benchmarkFunction();
const time = os.clock() - startTime;
result.benchmarkName = debug.getinfo(benchmarkFunction).short_src;
result.time = time;
return result;
}
export function compareRuntimeBenchmarks(
oldResults: RuntimeBenchmarkResult[],
newResults: RuntimeBenchmarkResult[]
): ComparisonInfo {
const summary =
"### runtime\n\n" +
compareNumericBenchmarks(
newResults,
oldResults,
"s",
result => result.time,
time => toFixed(time, 4)
);
const text = `### master\n\`\`\`json\n${json.encode(oldResults)}\n\`\`\`\n### commit\n\`\`\`json\n${json.encode(
newResults
)}\n\`\`\``;
return { summary, text };
}