Skip to content

Commit

Permalink
feat: allow comparisons if a command fails
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis authored and andrewrk committed Dec 2, 2024
1 parent d5b043d commit 229bea6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const usage_text =
\\ -d, --duration <ms> (default: 5000) how long to repeatedly sample each command
\\ --color <when> (default: auto) color output mode
\\ available options: 'auto', 'never', 'ansi'
\\ -f, --allow-failures (default: false) compare performance if a non-zero exit code is returned
\\
;

Expand Down Expand Up @@ -90,6 +91,7 @@ pub fn main() !void {
var commands = std.ArrayList(Command).init(arena);
var max_nano_seconds: u64 = std.time.ns_per_s * 5;
var color: ColorMode = .auto;
var allow_failures = false;

var arg_i: usize = 1;
while (arg_i < args.len) : (arg_i += 1) {
Expand Down Expand Up @@ -138,6 +140,8 @@ pub fn main() !void {
, .{next});
std.process.exit(1);
}
} else if (std.mem.eql(u8, arg, "-f") or std.mem.eql(u8, arg, "--allow-failures")) {
allow_failures = true;
} else {
std.debug.print("unrecognized argument: '{s}'\n{s}", .{ arg, usage_text });
std.process.exit(1);
Expand Down Expand Up @@ -247,7 +251,7 @@ pub fn main() !void {

switch (term) {
.Exited => |code| {
if (code != 0) {
if (code != 0 and !allow_failures) {
if (tty_conf != .no_color)
bar.clear() catch {};
std.debug.print("\nerror: Benchmark {d} command '{s}' failed with exit code {d}:\n", .{
Expand Down

0 comments on commit 229bea6

Please sign in to comment.