Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ jobs:
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'Benchmark.js Benchmark'
jsperformanceentry:
name: Run JsPerformanceEntry benchmark example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- run: npm ci
- run: npm run build
- name: Save previous data.js
run: |
git fetch origin gh-pages
git checkout gh-pages
cp ./dev/bench/data.js before_data.js
git checkout -
- name: Run benchmark
run: cd examples/jsperformanceentry && npm install && node bench.js | tee output.txt
- name: Store benchmark result
uses: ./
with:
name: JsPerformanceEntry Benchmark
tool: 'jsperformanceentry'
output-file-path: examples/jsperformanceentry/output.txt
skip-fetch-gh-pages: true
fail-on-alert: true
- run: node ./scripts/ci_validate_modification.js before_data.js 'JsPerformanceEntry Benchmark'
pytest-benchmark:
name: Run Pytest benchmark example
runs-on: ubuntu-latest
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/jsperformanceentry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: JsPerformanceEntry Example
on:
push:
branches:
- master

jobs:
benchmark:
name: Run JsPerformanceEntry benchmark example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- name: Run JsPerformanceEntry
run: cd examples/jsperformanceentry && npm install && node bench.js | tee output.txt
- name: Store JsPerformanceEntry result
uses: rhysd/github-action-benchmark@v1
with:
name: JsPerformanceEntry Benchmark
tool: 'jsperformanceentry'
output-file-path: examples/jsperformanceentry/output.txt
# Use personal access token instead of GITHUB_TOKEN due to https://github.community/t5/GitHub-Actions/Github-action-not-triggering-gh-pages-upon-push/td-p/26869/highlight/false
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@gsouquet'
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This action currently supports the following tools:
- [`cargo bench`][cargo-bench] for Rust projects
- `go test -bench` for Go projects
- [benchmark.js][benchmarkjs] for JavaScript/TypeScript projects
- [JsPerformanceEntry][[jsperformanceentry]] for JavaScript/TypeScript projects
- [pytest-benchmark][] for Python projects with [pytest][]
- [Google Benchmark Framework][google-benchmark] for C++ projects
- [Catch2][catch2] for C++ projects
Expand All @@ -34,14 +35,15 @@ Multiple languages in the same repository are supported for polyglot projects.
Example projects for each language are in [examples/](./examples) directory. Live example workflow
definitions are in [.github/workflows/](./.github/workflows) directory. Live workflows are:

| Language | Workflow | Example Project |
|--------------|-----------------------------------------------------------------------------------------|------------------------------------------------|
| Rust | [![Rust Example Workflow][rust-badge]][rust-workflow-example] | [examples/rust](./examples/rust) |
| Go | [![Go Example Workflow][go-badge]][go-workflow-example] | [examples/go](./examples/go) |
| JavaScript | [![JavaScript Example Workflow][benchmarkjs-badge]][benchmarkjs-workflow-example] | [examples/benchmarkjs](./examples/benchmarkjs) |
| Python | [![pytest-benchmark Example Workflow][pytest-benchmark-badge]][pytest-workflow-example] | [examples/pytest](./examples/pytest) |
| C++ | [![C++ Example Workflow][cpp-badge]][cpp-workflow-example] | [examples/cpp](./examples/cpp) |
| C++ (Catch2) | [![C++ Catch2 Example Workflow][catch2-badge]][catch2-workflow-example] | [examples/catch2](./examples/catch2) |
| Language | Workflow | Example Project |
|--------------|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| Rust | [![Rust Example Workflow][rust-badge]][rust-workflow-example] | [examples/rust](./examples/rust) |
| Go | [![Go Example Workflow][go-badge]][go-workflow-example] | [examples/go](./examples/go) |
| JavaScript | [![JavaScript Example Workflow][benchmarkjs-badge]][benchmarkjs-workflow-example] | [examples/benchmarkjs](./examples/benchmarkjs) |
| JavaScript | [![JsPerformance Example Workflow][jsperformanceentry-badge]][benchmarkjs-workflow-example] | [examples/jsperformanceentry](./examples/jsperformanceentry) |
| Python | [![pytest-benchmark Example Workflow][pytest-benchmark-badge]][pytest-workflow-example] | [examples/pytest](./examples/pytest) |
| C++ | [![C++ Example Workflow][cpp-badge]][cpp-workflow-example] | [examples/cpp](./examples/cpp) |
| C++ (Catch2) | [![C++ Catch2 Example Workflow][catch2-badge]][catch2-workflow-example] | [examples/catch2](./examples/catch2) |

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

Expand Down Expand Up @@ -300,6 +302,7 @@ and store it to file. Then specify the file path to `output-file-path` input.
- [`cargo bench` for Rust projects](./examples/rust/README.md)
- [`go test` for Go projects](./examples/go/README.md)
- [Benchmark.js for JavaScript/TypeScript projects](./examples/benchmarkjs/README.md)
- [JsPerformanceEntry for JavaScript/TypeScript projects](./examples/jsperformanceentry/README.md)
- [pytest-benchmark for Python projects with pytest](./examples/pytest/README.md)
- [Google Benchmark Framework for C++ projects](./examples/cpp/README.md)

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

Tool for running benchmark. The value must be one of `"cargo"`, `"go"`, `"benchmarkjs"`, `"pytest"`,
Tool for running benchmark. The value must be one of `"cargo"`, `"go"`, `"benchmarkjs"`, `"jsperformanceentry"`, `"pytest"`,
`"googlecpp"`, `"catch2"`.

#### `output-file-path` (Required)
Expand Down Expand Up @@ -563,12 +566,14 @@ Every release will appear on your GitHub notifications page.
[rust-badge]: https://github.com/rhysd/github-action-benchmark/workflows/Rust%20Example/badge.svg
[go-badge]: https://github.com/rhysd/github-action-benchmark/workflows/Go%20Example/badge.svg
[benchmarkjs-badge]: https://github.com/rhysd/github-action-benchmark/workflows/Benchmark.js%20Example/badge.svg
[jsperformanceentry-badge]: https://github.com/rhysd/github-action-benchmark/workflows/JsPerformanceEntry%20Example/badge.svg
[pytest-benchmark-badge]: https://github.com/rhysd/github-action-benchmark/workflows/Python%20Example%20with%20pytest/badge.svg
[cpp-badge]: https://github.com/rhysd/github-action-benchmark/workflows/C%2B%2B%20Example/badge.svg
[catch2-badge]: https://github.com/rhysd/github-action-benchmark/workflows/Catch2%20C%2B%2B%20Example/badge.svg
[github-action]: https://github.com/features/actions
[cargo-bench]: https://doc.rust-lang.org/cargo/commands/cargo-bench.html
[benchmarkjs]: https://benchmarkjs.com/
[jsperformanceentry]: https://developer.mozilla.org/docs/Web/API/Performance
[gh-pages]: https://pages.github.com/
[examples-page]: https://rhysd.github.io/github-action-benchmark/dev/bench/
[pytest-benchmark]: https://pypi.org/project/pytest-benchmark/
Expand All @@ -577,6 +582,7 @@ Every release will appear on your GitHub notifications page.
[rust-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Rust+Example%22
[go-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Go+Example%22
[benchmarkjs-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Benchmark.js+Example%22
[jsperformanceentry-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22JsPerformanceEntry%20Example%22
[pytest-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Python+Example+with+pytest%22
[cpp-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22C%2B%2B+Example%22
[catch2-workflow-example]: https://github.com/rhysd/github-action-benchmark/actions?query=workflow%3A%22Catch2+C%2B%2B+Example%22
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inputs:
required: true
default: 'Benchmark'
tool:
description: 'Tool to use get benchmark output. One of "cargo", "go", "benchmarkjs", "pytest"'
description: 'Tool to use get benchmark output. One of "cargo", "go", "benchmarkjs", "jsperformanceentry", "pytest"'
required: true
output-file-path:
description: 'A path to file which contains the benchmark output'
Expand Down
2 changes: 2 additions & 0 deletions examples/jsperformanceentry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/package-lock.json
56 changes: 56 additions & 0 deletions examples/jsperformanceentry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Node.js example for benchmarking with the [JS performance API](https://developer.mozilla.org/docs/Web/API/Performance)
======================================================================================================================

- [Workflow for this example](../../.github/workflows/jsperformanceentry.yml)
- [Action log of this example](#TODO)
- [Benchmark results on GitHub pages](#TODO)

This directory shows how to use [`github-action-benchmark`](https://github.com/rhysd/github-action-benchmark)
with [JS performance API](https://developer.mozilla.org/docs/Web/API/Performance).

## Run benchmarks

Documentation for usage of the performance API:

- In a browser context: https://developer.mozilla.org/docs/Web/API/Performance
- In a Node.js context: https://nodejs.org/api/perf_hooks.html

Prepare script `bench.js` as follows:

e.g.

```javascript

performance.mark('start');

functionToBenchmark(25);

performance.mark('end');
performance.measure('eventName', 'start', 'end');

const entries = JSON.stringify(performance.getEntriesByType('measure'));
console.log(entries);
```

Run the script in workflow:

e.g.

```yaml
- name: Run benchmark
run: node bench.js | tee output.txt
```

## Process benchmark results

Store the benchmark results with step using the action. Please set `benchmarkjs` to `tool` input.

```yaml
- name: Store benchmark result
uses: rhysd/github-action-benchmark@v1
with:
tool: 'benchmarkjs'
output-file-path: output.txt
```

Please read ['How to use' section](https://github.com/rhysd/github-action-benchmark#how-to-use) for common usage.
18 changes: 18 additions & 0 deletions examples/jsperformanceentry/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const {
performance, // available in web browsers too
PerformanceObserver
} = require('perf_hooks');
const { fib } = require('./index');

const obs = new PerformanceObserver((perfObserverList, observer) => {
const entries = perfObserverList.getEntries();
console.log(JSON.stringify(entries));
observer.disconnect();
process.exit(0);
});
obs.observe({ entryTypes: ['measure'] });

performance.mark('start:fib(25)');
fib(25);
performance.mark('end:fib(25)');
performance.measure('fib(25)', 'start:fib(25)', 'end:fib(25)');
8 changes: 8 additions & 0 deletions examples/jsperformanceentry/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function fib(n) {
if (n <= 1) {
return 1;
}
return fib(n - 2) + fib(n - 1);
}

exports.fib = fib;
12 changes: 12 additions & 0 deletions examples/jsperformanceentry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "performanceentry-example",
"private": true,
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Germain Souquet <germain@souquet.com>",
"license": "MIT"
}
12 changes: 10 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promises as fs } from 'fs';
import * as os from 'os';
import * as path from 'path';

export type ToolType = 'cargo' | 'go' | 'benchmarkjs' | 'pytest' | 'googlecpp' | 'catch2';
export type ToolType = 'cargo' | 'go' | 'benchmarkjs' | 'jsperformanceentry' | 'pytest' | 'googlecpp' | 'catch2';
export interface Config {
name: string;
tool: ToolType;
Expand All @@ -24,7 +24,15 @@ export interface Config {
maxItemsInChart: number | null;
}

export const VALID_TOOLS: ToolType[] = ['cargo', 'go', 'benchmarkjs', 'pytest', 'googlecpp', 'catch2'];
export const VALID_TOOLS: ToolType[] = [
'cargo',
'go',
'benchmarkjs',
'jsperformanceentry',
'pytest',
'googlecpp',
'catch2',
];
const RE_UINT = /^\d+$/;

function validateToolType(tool: string): asserts tool is ToolType {
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',
jsperformanceentry: '#64bd25',
pytest: '#3572a5',
googlecpp: '#f34b7d',
catch2: '#f34b7d',
Expand Down
28 changes: 28 additions & 0 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ export interface PytestBenchmarkJson {
version: string;
}

export interface JsPerformanceEntryJson {
name: string;
entryType: 'element' | 'frame' | 'navigation' | 'resource' | 'mark' | 'measure' | 'paint' | 'longtask';
startTime: number;
duration: number;
}

function getHumanReadableUnitValue(seconds: number): [number, string] {
if (seconds < 1.0e-6) {
return [seconds * 1e9, 'nsec'];
Expand Down Expand Up @@ -266,6 +273,24 @@ function extractBenchmarkJsResult(output: string): BenchmarkResult[] {
return ret;
}

function extractJsPerformanceEntryResult(output: string): BenchmarkResult[] {
let json: JsPerformanceEntryJson[];
try {
json = JSON.parse(output);
} catch (err) {
throw new Error(`Output file for 'jsperformanceentry' invalid: ${err.message}`);
}

return json.map(entry => {
return {
name: entry.name,
value: entry.duration,
unit: 'ms',
extra: `type: ${entry.entryType}`,
};
});
}

function extractPytestResult(output: string): BenchmarkResult[] {
try {
const json: PytestBenchmarkJson = JSON.parse(output);
Expand Down Expand Up @@ -430,6 +455,9 @@ export async function extractResult(config: Config): Promise<Benchmark> {
case 'benchmarkjs':
benches = extractBenchmarkJsResult(output);
break;
case 'jsperformanceentry':
benches = extractJsPerformanceEntryResult(output);
break;
case 'pytest':
benches = extractPytestResult(output);
break;
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 'jsperformanceentry':
return false;
case 'pytest':
return true;
case 'googlecpp':
Expand Down
14 changes: 14 additions & 0 deletions test/data/extract/jsperformanceentry_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "fib(10)",
"duration": 1234,
"startTime": 1337,
"entryType": "measure"
},
{
"name": "fib(20)",
"duration": 1234,
"startTime": 0,
"entryType": "measure"
}
]
17 changes: 17 additions & 0 deletions test/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ describe('extractResult()', function() {
},
],
},
{
tool: 'jsperformanceentry',
expected: [
{
name: 'fib(10)',
unit: 'ms',
value: 1234,
extra: 'type: measure',
},
{
name: 'fib(20)',
unit: 'ms',
value: 1234,
extra: 'type: measure',
},
],
},
{
tool: 'pytest',
expected: [
Expand Down