Skip to content

Commit

Permalink
Added benchmark luau support (#123)
Browse files Browse the repository at this point in the history
* added benchmark luau support
* added unit tests for luau benchmarks output
* updated README.md with the new tool
  • Loading branch information
AllanJeremy authored May 11, 2022
1 parent 4cd86fc commit f6baee1
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "^_" }],
"@typescript-eslint/naming-convention": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This action currently supports the following tools:
- [Catch2][catch2] for C++ projects
- [BenchmarkTools.jl][] for Julia packages
- [Benchmark.Net][benchmarkdotnet] for .Net projects
- [benchmarkluau](https://github.com/Roblox/luau/tree/master/bench) for Luau projects
- Custom benchmarks where either 'biggerIsBetter' or 'smallerIsBetter'

Multiple languages in the same repository are supported for polyglot projects.
Expand All @@ -47,6 +48,7 @@ definitions are in [.github/workflows/](./.github/workflows) directory. Live wor
| C++ (Catch2) | [![C++ Catch2 Example Workflow][catch2-badge]][catch2-workflow-example] | [examples/catch2](./examples/catch2) |
| Julia | [![Julia Example][julia-badge]][julia-workflow-example] | [examples/julia](./examples/julia) |
| .Net | [![C# Benchmark.Net Example Workflow][benchmarkdotnet-badge]][benchmarkdotnet-workflow-example] | [examples/benchmarkdotnet](./examples/benchmarkdotnet) |
| Luau | Coming soon | Coming soon |

All benchmark charts from above workflows are gathered in GitHub pages:

Expand Down Expand Up @@ -330,6 +332,7 @@ and store it to file. Then specify the file path to `output-file-path` input.
- [catch2 for C++ projects](./examples/cpp/README.md)
- [BenchmarkTools.jl for Julia projects](./examples/julia/README.md)
- [Benchmark.Net for .Net projects](./examples/benchmarkdotnet/README.md)
- [benchmarkluau for Luau projects](#) - Examples for this are still a work in progress.

These examples are run in workflows of this repository as described in the 'Examples' section above.

Expand All @@ -351,7 +354,7 @@ Name of the benchmark. This value must be identical across all benchmarks in you
- Default: N/A

Tool for running benchmark. The value must be one of `"cargo"`, `"go"`, `"benchmarkjs"`, `"pytest"`,
`"googlecpp"`, `"catch2"`, `"julia"`, `"benchmarkdotnet"`, `"customBiggerIsBetter"`, `"customSmallerIsBetter"`.
`"googlecpp"`, `"catch2"`, `"julia"`, `"benchmarkdotnet"`,`"benchmarkluau"`, `"customBiggerIsBetter"`, `"customSmallerIsBetter"`.

#### `output-file-path` (Required)

Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type ToolType =
| 'cargo'
| 'go'
| 'benchmarkjs'
| 'benchmarkluau'
| 'pytest'
| 'googlecpp'
| 'catch2'
Expand Down
1 change: 1 addition & 0 deletions src/default_index_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const DEFAULT_INDEX_HTML = String.raw`<!DOCTYPE html>
cargo: '#dea584',
go: '#00add8',
benchmarkjs: '#f1e05a',
benchmarkluau: '#000080',
pytest: '#3572a5',
googlecpp: '#f34b7d',
catch2: '#f34b7d',
Expand Down
24 changes: 24 additions & 0 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,27 @@ function extractCustomBenchmarkResult(output: string): BenchmarkResult[] {
}
}

function extractLuauBenchmarkResult(output: string): BenchmarkResult[] {
const lines = output.split(/\n/);
const results: BenchmarkResult[] = [];

output;
for (const line of lines) {
if (!line.startsWith('SUCCESS')) continue;
const [_0, name, _2, valueStr, _4, range, _6, extra] = line.split(/\s+/);

results.push({
name: name,
value: parseFloat(valueStr),
unit: valueStr.replace(/.[0-9]+/g, ''),
range: ${range}`,
extra: extra,
});
}

return results;
}

export async function extractResult(config: Config): Promise<Benchmark> {
const output = await fs.readFile(config.outputFilePath, 'utf8');
const { tool, githubToken } = config;
Expand Down Expand Up @@ -629,6 +650,9 @@ export async function extractResult(config: Config): Promise<Benchmark> {
case 'customSmallerIsBetter':
benches = extractCustomBenchmarkResult(output);
break;
case 'benchmarkluau':
benches = extractLuauBenchmarkResult(output);
break;
default:
throw new Error(`FATAL: Unexpected tool: '${tool}'`);
}
Expand Down
2 changes: 2 additions & 0 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function biggerIsBetter(tool: ToolType): boolean {
return false;
case 'benchmarkjs':
return true;
case 'benchmarkluau':
return false;
case 'pytest':
return true;
case 'googlecpp':
Expand Down
12 changes: 12 additions & 0 deletions test/data/extract/benchmarkluau_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SUCCESS: base64 : 15.041ms +/- 0.636% on luau
SUCCESS: chess : 69.560ms +/- 0.212% on luau
SUCCESS: life : 85.089ms +/- 0.187% on luau

==================================================RESULTS==================================================
Test | Min | Average | StdDev% | Driver
-----------------------+-------------+-------------+------------+--------
base64 | 14.831ms | 15.041ms | 0.636% | luau
chess | 69.106ms | 69.560ms | 0.212% | luau
life | 84.696ms | 85.089ms | 0.187% | luau
Total | 168.630ms | 169.690ms | --- | luau
---
26 changes: 26 additions & 0 deletions test/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,32 @@ describe('extractResult()', function () {
},
],
},
{
tool: 'benchmarkluau',
expected: [
{
name: 'base64',
range: '±0.636%',
unit: 'ms',
value: 15.041,
extra: 'luau',
},
{
name: 'chess',
range: '±0.212%',
unit: 'ms',
value: 69.56,
extra: 'luau',
},
{
name: 'life',
range: '±0.187%',
unit: 'ms',
value: 85.089,
extra: 'luau',
},
],
},
{
tool: 'pytest',
expected: [
Expand Down

0 comments on commit f6baee1

Please sign in to comment.