Skip to content

Commit 8e6a557

Browse files
committed
Add support for lit
1 parent e3c6616 commit 8e6a557

File tree

14 files changed

+286
-0
lines changed

14 files changed

+286
-0
lines changed

.github/workflows/ci.yml

+36
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,42 @@ jobs:
404404
github-token: ${{ secrets.GITHUB_TOKEN }}
405405
comment-on-alert: true
406406
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'Criterion.rs Benchmark'
407+
408+
lit-benchmark:
409+
name: Run lit benchmark example
410+
runs-on: ubuntu-latest
411+
steps:
412+
- uses: actions/checkout@v4
413+
- uses: actions/setup-node@v4
414+
with:
415+
node-version: 20
416+
cache: 'npm'
417+
- run: npm ci
418+
- run: npm run build
419+
- uses: actions/setup-python@v5
420+
with:
421+
python-version: '3.13'
422+
- run: pip install lit
423+
- name: Run benchmark
424+
run: lit examples/lit --resultdb-output examples/lit/output.json
425+
- name: Save previous data.js
426+
run: |
427+
git fetch origin gh-pages
428+
git checkout gh-pages
429+
cp ./dev/bench/data.js before_data.js
430+
git checkout -
431+
- name: Store benchmark result
432+
uses: ./
433+
with:
434+
name: lit benchmark
435+
tool: 'lit'
436+
output-file-path: examples/lit/output.json
437+
skip-fetch-gh-pages: true
438+
fail-on-alert: true
439+
summary-always: true
440+
github-token: ${{ secrets.GITHUB_TOKEN }}
441+
comment-on-alert: true
442+
- run: node ./dist/scripts/ci_validate_modification.js before_data.js 'lit benchmark'
407443

408444
only-alert-with-cache:
409445
name: Run alert check with actions/cache

.github/workflows/lit.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: lit Example
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
permissions:
8+
contents: write
9+
deployments: write
10+
11+
jobs:
12+
benchmark:
13+
name: Run lit benchmark example
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.13'
20+
- run: pip install lit
21+
- name: Run benchmark
22+
run: lit examples/lit --resultdb-output examples/lit/output.json
23+
- name: Store benchmark result
24+
uses: benchmark-action/github-action-benchmark@v1
25+
with:
26+
name: lit benchmark result
27+
tool: 'lit'
28+
output-file-path: examples/lit/output.json
29+
# Use personal access token instead of GITHUB_TOKEN due to https://github.community/t/github-action-not-triggering-gh-pages-upon-push/16096
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
auto-push: true
32+
# Show alert with commit comment on detecting possible performance regression
33+
alert-threshold: '200%'
34+
comment-on-alert: true
35+
fail-on-alert: true
36+
alert-comment-cc-users: '@tgymnich'
37+
38+
- name: Store benchmark result - separate results repo
39+
uses: benchmark-action/github-action-benchmark@v1
40+
with:
41+
name: lit benchmark result
42+
tool: 'lit'
43+
output-file-path: examples/lit/output.json
44+
# Use personal access token instead of GITHUB_TOKEN due to https://github.community/t/github-action-not-triggering-gh-pages-upon-push/16096
45+
github-token: ${{ secrets.BENCHMARK_ACTION_BOT_TOKEN }}
46+
auto-push: true
47+
# Show alert with commit comment on detecting possible performance regression
48+
alert-threshold: '200%'
49+
comment-on-alert: true
50+
fail-on-alert: true
51+
alert-comment-cc-users: '@tgymnich'
52+
gh-repository: 'github.com/benchmark-action/github-action-benchmark-results'

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This action currently supports the following tools:
2626
- [Benchmark.Net][benchmarkdotnet] for .Net projects
2727
- [benchmarkluau](https://github.com/Roblox/luau/tree/master/bench) for Luau projects
2828
- [JMH][jmh] for Java projects
29+
- [lit][lit] for projects using the LLVM Integrated Tester
2930
- Custom benchmarks where either 'biggerIsBetter' or 'smallerIsBetter'
3031

3132
Multiple languages in the same repository are supported for polyglot projects.
@@ -51,6 +52,8 @@ definitions are in [.github/workflows/](./.github/workflows) directory. Live wor
5152
| .Net | [![C# Benchmark.Net Example Workflow][benchmarkdotnet-badge]][benchmarkdotnet-workflow-example] | [examples/benchmarkdotnet](./examples/benchmarkdotnet) |
5253
| Java | [![Java Example Workflow][java-badge]][java-workflow-example] | [examples/java](./examples/java) |
5354
| Luau | Coming soon | Coming soon |
55+
| lit | [lit Example Workflow][lit-workflow-example] | [examples/lit](./examples/lit) |
56+
5457

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

@@ -362,6 +365,7 @@ and store it to file. Then specify the file path to `output-file-path` input.
362365
- [BenchmarkTools.jl for Julia projects](./examples/julia/README.md)
363366
- [Benchmark.Net for .Net projects](./examples/benchmarkdotnet/README.md)
364367
- [benchmarkluau for Luau projects](#) - Examples for this are still a work in progress.
368+
- [lit](./examples/lit/README.md)
365369

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

@@ -660,6 +664,7 @@ Every release will appear on your GitHub notifications page.
660664
[catch2-workflow-example]: https://github.com/benchmark-action/github-action-benchmark/actions?query=workflow%3A%22Catch2+C%2B%2B+Example%22
661665
[julia-workflow-example]: https://github.com/benchmark-action/github-action-benchmark/actions?query=workflow%3A%22Julia+Example+with+BenchmarkTools.jl%22
662666
[java-workflow-example]: https://github.com/benchmark-action/github-action-benchmark/actions?query=workflow%3A%22JMH+Example%22
667+
[lit-workflow-example]: https://github.com/benchmark-action/github-action-benchmark/actions?query=workflow%3A%22lit+Example%22
663668
[help-watch-release]: https://docs.github.com/en/github/receiving-notifications-about-activity-on-github/watching-and-unwatching-releases-for-a-repository
664669
[help-github-token]: https://docs.github.com/en/actions/security-guides/automatic-token-authentication
665670
[minimal-workflow-example]: https://github.com/benchmark-action/github-action-benchmark/actions?query=workflow%3A%22Example+for+minimal+setup%22
@@ -673,4 +678,5 @@ Every release will appear on your GitHub notifications page.
673678
[benchmarkdotnet]: https://benchmarkdotnet.org
674679
[benchmarkdotnet-badge]: https://github.com/benchmark-action/github-action-benchmark/actions/workflows/benchmarkdotnet.yml/badge.svg
675680
[benchmarkdotnet-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Benchmark.Net+Example%22
681+
[lit]: https://llvm.org/docs/CommandGuide/lit.html
676682
[job-summaries]: https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/

examples/lit/README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# lit - LLVM Integrated Tester Example
2+
3+
- [lit docs](https://llvm.org/docs/CommandGuide/lit.html)
4+
- [Workflow for this example](../../.github/workflows/lit.yml)
5+
6+
This directory shows how to use [`github-action-benchmark`](https://github.com/benchmark-action/github-action-benchmark)
7+
with [lit](https://llvm.org/docs/CommandGuide/lit.html).
8+
9+
## Run benchmarks
10+
11+
Install dependencies with `venv` package using Python3.
12+
13+
```sh
14+
$ python -m venv venv
15+
$ source venv/bin/activate
16+
$ pip install lit
17+
```
18+
19+
Setup your test suite. In this example it consists of a configuration file for lit `lit.cfg` and two tests `a.txt` and `b.txt` containing one RUN line each.
20+
21+
e.g
22+
23+
```python
24+
import lit.formats
25+
26+
config.name = "time-tests"
27+
config.suffixes = [".txt"]
28+
config.test_format = lit.formats.ShTest()
29+
config.test_source_root = None
30+
config.test_exec_root = None
31+
```
32+
33+
```
34+
# RUN: true
35+
```
36+
37+
```
38+
# RUN: sleep 1
39+
```
40+
41+
And run the test suite with `--resultdb-output` in workflow. The JSON file will be an input to github-action-benchmark.
42+
43+
e.g.
44+
45+
```yaml
46+
- name: Run benchmark
47+
run: lit examples/lit --resultdb-output output.json
48+
```
49+
50+
## Process benchmark results
51+
52+
Store the benchmark results with step using the action. Please set `tool` to `lit` input and pass the path to the output file.
53+
54+
```yaml
55+
- name: Store benchmark result
56+
uses: benchmark-action/github-action-benchmark@v1
57+
with:
58+
tool: 'lit'
59+
output-file-path: output.json
60+
```
61+
62+
Please read ['How to use' section](https://github.com/benchmark-action/github-action-benchmark#how-to-use) for common usage.

examples/lit/a.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# RUN: true

examples/lit/b.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# RUN: sleep 1

examples/lit/lit.cfg

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- Python -*-
2+
3+
import lit.formats
4+
5+
config.name = "time-tests"
6+
config.suffixes = [".txt"]
7+
config.test_format = lit.formats.ShTest()
8+
config.test_source_root = None
9+
config.test_exec_root = None

src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const VALID_TOOLS = [
4040
'benchmarkdotnet',
4141
'customBiggerIsBetter',
4242
'customSmallerIsBetter',
43+
'lit',
4344
] as const;
4445
const RE_UINT = /^\d+$/;
4546

src/default_index_html.ts

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const DEFAULT_INDEX_HTML = String.raw`<!DOCTYPE html>
123123
benchmarkdotnet: '#178600',
124124
customBiggerIsBetter: '#38ff38',
125125
customSmallerIsBetter: '#ff3838',
126+
lit: '#185619',
126127
_: '#333333'
127128
};
128129

src/extract.ts

+39
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ export interface BenchmarkDotNetBenchmarkJson {
222222
Benchmarks: BenchmarkDotnetBenchmark[];
223223
}
224224

225+
export interface LitBenchmarkJson {
226+
__version__: number[];
227+
elapsed: number;
228+
tests: Array<{
229+
artifacts: {
230+
artifact_content_in_request: {
231+
contents: string;
232+
};
233+
};
234+
duration: string;
235+
expected: boolean;
236+
start_time: string;
237+
status: string;
238+
summary_html: string;
239+
testId: string;
240+
}>;
241+
}
242+
225243
function getHumanReadableUnitValue(seconds: number): [number, string] {
226244
if (seconds < 1.0e-6) {
227245
return [seconds * 1e9, 'nsec'];
@@ -690,6 +708,24 @@ function extractLuauBenchmarkResult(output: string): BenchmarkResult[] {
690708
return results;
691709
}
692710

711+
function extractLitBenchmarkResult(output: string): BenchmarkResult[] {
712+
let json: LitBenchmarkJson;
713+
try {
714+
json = JSON.parse(output);
715+
} catch (err: any) {
716+
throw new Error(
717+
`Output file for 'lit' must be JSON file generated by --resultdb-output option: ${err.message}`,
718+
);
719+
}
720+
return json.tests.map((b) => {
721+
const name = b.testId;
722+
const value = parseFloat(b.duration.substring(0, b.duration.length - 2));
723+
const unit = 's';
724+
const extra = `expected: ${b.expected}\nstart_time: ${b.start_time}\nstatus: ${b.status}\nsummary_html: ${b.summary_html}`;
725+
return { name, value, unit, extra };
726+
});
727+
}
728+
693729
export async function extractResult(config: Config): Promise<Benchmark> {
694730
const output = await fs.readFile(config.outputFilePath, 'utf8');
695731
const { tool, githubToken, ref } = config;
@@ -732,6 +768,9 @@ export async function extractResult(config: Config): Promise<Benchmark> {
732768
case 'benchmarkluau':
733769
benches = extractLuauBenchmarkResult(output);
734770
break;
771+
case 'lit':
772+
benches = extractLitBenchmarkResult(output);
773+
break;
735774
default:
736775
throw new Error(`FATAL: Unexpected tool: '${tool}'`);
737776
}

src/write.ts

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function biggerIsBetter(tool: ToolType): boolean {
8181
return false;
8282
case 'benchmarkdotnet':
8383
return false;
84+
case 'lit':
85+
return false;
8486
case 'customBiggerIsBetter':
8587
return true;
8688
case 'customSmallerIsBetter':

test/__snapshots__/extract.spec.ts.snap

+35
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,41 @@ params={"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample
887887
}
888888
`;
889889

890+
exports[`extractResult() extracts benchmark output from lit - lit_output.json 1`] = `
891+
{
892+
"benches": [
893+
{
894+
"extra": "expected: true
895+
start_time: 2025-01-19T20:13:43.882058Z
896+
status: PASS
897+
summary_html: <p><text-artifact artifact-id="artifact-content-in-request"></p>",
898+
"name": "time-tests :: b.txt",
899+
"unit": "s",
900+
"value": 1.0095539,
901+
},
902+
{
903+
"extra": "expected: true
904+
start_time: 2025-01-19T20:13:43.882072Z
905+
status: PASS
906+
summary_html: <p><text-artifact artifact-id="artifact-content-in-request"></p>",
907+
"name": "time-tests :: a.txt",
908+
"unit": "s",
909+
"value": 0.00366711,
910+
},
911+
],
912+
"commit": {
913+
"author": null,
914+
"committer": null,
915+
"id": "123456789abcdef",
916+
"message": "this is dummy",
917+
"timestamp": "dummy timestamp",
918+
"url": "https://github.com/dummy/repo",
919+
},
920+
"date": 1712131503296,
921+
"tool": "lit",
922+
}
923+
`;
924+
890925
exports[`extractResult() extracts benchmark output from pytest - pytest_output.json 1`] = `
891926
{
892927
"benches": [

test/data/extract/lit_output.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"__version__": [
3+
18,
4+
1,
5+
8
6+
],
7+
"elapsed": 1.0956830978393555,
8+
"tests": [
9+
{
10+
"artifacts": {
11+
"artifact-content-in-request": {
12+
"contents": "RXhpdCBDb2RlOiAwCgpDb21tYW5kIE91dHB1dCAoc3Rkb3V0KToKLS0KIyBSVU46IGF0IGxpbmUgMQpzbGVlcCAxCiMgZXhlY3V0ZWQgY29tbWFuZDogc2xlZXAgMQoKLS0K"
13+
}
14+
},
15+
"duration": "1.009553909s",
16+
"expected": true,
17+
"start_time": "2025-01-19T20:13:43.882058Z",
18+
"status": "PASS",
19+
"summary_html": "<p><text-artifact artifact-id=\"artifact-content-in-request\"></p>",
20+
"testId": "time-tests :: b.txt"
21+
},
22+
{
23+
"artifacts": {
24+
"artifact-content-in-request": {
25+
"contents": "RXhpdCBDb2RlOiAwCgpDb21tYW5kIE91dHB1dCAoc3Rkb3V0KToKLS0KIyBSVU46IGF0IGxpbmUgMQp0cnVlCiMgZXhlY3V0ZWQgY29tbWFuZDogdHJ1ZQoKLS0K"
26+
}
27+
},
28+
"duration": "0.003667116s",
29+
"expected": true,
30+
"start_time": "2025-01-19T20:13:43.882072Z",
31+
"status": "PASS",
32+
"summary_html": "<p><text-artifact artifact-id=\"artifact-content-in-request\"></p>",
33+
"testId": "time-tests :: a.txt"
34+
}
35+
]
36+
}
37+

test/extract.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ describe('extractResult()', function () {
135135
tool: 'benchmarkdotnet',
136136
file: 'benchmarkdotnet.json',
137137
},
138+
{
139+
tool: 'lit',
140+
file: 'lit_output.json',
141+
},
138142
{
139143
tool: 'customBiggerIsBetter',
140144
file: 'customBiggerIsBetter_output.json',

0 commit comments

Comments
 (0)