Skip to content
Open
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ option:
hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'
```

For large parameter sets, values can be read one line at a time from a file with
`--parameter-file`:

```
hyperfine --parameter-file compiler compilers.txt '{compiler} -O2 main.cpp'
```
Both LF and CRLF line endings are supported. The file is processed with a buffered reader, so its
full contents are not held in memory.

### Intermediate shell

By default, commands are executed using a predefined shell (`/bin/sh` on Unix, `cmd.exe` on Windows).
Expand Down
19 changes: 15 additions & 4 deletions src/benchmark/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,25 @@ impl<'a> Scheduler<'a> {

executor.calibrate()?;

for (number, cmd) in reference.iter().chain(self.commands.iter()).enumerate() {
self.results
.push(Benchmark::new(number, cmd, self.options, &*executor).run()?);
let mut number = 0;
let results = &mut self.results;
let options = self.options;
let export_manager = self.export_manager;
let mut run_command = |cmd: &Command<'a>| -> Result<()> {
results.push(Benchmark::new(number, cmd, options, &*executor).run()?);

// We export results after each individual benchmark, because
// we would risk losing them if a later benchmark fails.
self.export_manager.write_results(&self.results, true)?;
export_manager.write_results(results, true)?;
number += 1;

Ok(())
};

if let Some(reference) = reference.as_ref() {
run_command(reference)?;
}
self.commands.try_for_each(run_command)?;

Ok(())
}
Expand Down
20 changes: 20 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ fn build_command() -> Command {
possible parameter combinations.\n"
),
)
.arg(
Arg::new("parameter-file")
.long("parameter-file")
.action(ArgAction::Set)
.allow_hyphen_values(true)
.value_names(["VAR", "FILE"])
.conflicts_with_all([
"parameter-scan",
"parameter-step-size",
"parameter-list",
])
.help(
"Perform benchmark runs for each line in FILE. Replaces the string '{VAR}' \
in each command by the current line. FILE is processed line by line, so its \
full contents are not held in memory.\n\n Example: hyperfine \
--parameter-file compiler compilers.txt '{compiler} -O2 main.cpp'\n\nThis \
performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp' if FILE \
contains the lines 'gcc' and 'clang'.",
),
)
.arg(
Arg::new("shell")
.long("shell")
Expand Down
Loading