Skip to content

Commit 41aa874

Browse files
authored
fix blacha#6
1 parent 2d133c3 commit 41aa874

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Create a `.hyperfine.json`
2121
```json
2222
[
2323
{ "name": "sleep", "command": "sleep 0.1" },
24-
{ "name": "node", "command": "node -e 'console.log()'" }
24+
{ "name": "node", "command": "node -e 'console.log()'", "extraArgs": { "shell": "zsh" } }
2525
]
2626
```
2727

hyperfine.example.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
[
2-
{ "name": "sleep", "command": "sleep 0.1" },
3-
{ "name": "node", "command": "node -e 'console.log()'" }
4-
]
2+
{
3+
"name": "sleep",
4+
"command": "sleep 0.1"
5+
},
6+
{
7+
"name": "node",
8+
"command": "node -e 'console.log()'"
9+
},
10+
{
11+
"name": "extra arguments test",
12+
"command": "for i in {1..10000}; do echo test; done",
13+
"extraArgs": {
14+
"shell": "zsh",
15+
"L": "compiler gcc,clang"
16+
}
17+
}
18+
]

src/action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type HyperfineConfigFile = HyperfineConfig[];
1313
export interface HyperfineConfig {
1414
name: string;
1515
command: string;
16+
extraArgs: any[]
1617
}
1718

1819
export interface HyperfineResultSuite {
@@ -92,7 +93,7 @@ async function main(): Promise<void> {
9293

9394
for (const suite of config) {
9495
core.debug(`Starting benchmark: ${suite.name}`);
95-
const res = await Hyperfine.run(suite.command);
96+
const res = await Hyperfine.run(suite.command, suite.extraArgs);
9697
const count = res.times?.length ?? 0;
9798
delete res.times;
9899
benchmark.results.push({

src/hyperfine/hyperfine.run.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ export async function waitForChildProcess(cmd: string): Promise<string> {
4646
});
4747
}
4848

49-
export async function runHyperfine(cmd: string): Promise<HyperFineResult> {
49+
export async function runHyperfine(cmd: string, extraArgs: any): Promise<HyperFineResult> {
50+
//extraArgs example: {runs: "3", prepare: 5, shell: "zsh", "N": true}
5051
const HyperFineCommand = await findHyperfine();
5152

5253
const outputJsonFile = './' + randomBytes(10).toString('hex') + '.json';
53-
const hyperfineExecute = [HyperFineCommand, `--export-json ${outputJsonFile}`, `'${cmd}'`]; // TODO escape \'
54+
const hyperfineExecute = [HyperFineCommand, `--export-json ${outputJsonFile}`,
55+
Object.entries(extraArgs).map((e: any) => `${e[0].length == 1 ? `-${e[0]}` : `--${e[0]}`}${isNaN(e[1]) ? ' ' + JSON.stringify(e[1]) : (typeof e[1] == "boolean") ? "" : ' ' + e[1]}`).join(" "),
56+
`${JSON.stringify(cmd)}`];
5457

5558
const buffer = await waitForChildProcess(hyperfineExecute.join(' '));
5659
console.log(buffer);

0 commit comments

Comments
 (0)