Skip to content

Commit

Permalink
added an argument (-w, --warmup) to do a warmup run of every command …
Browse files Browse the repository at this point in the history
…before mesuring
  • Loading branch information
SuSonicTH committed Jan 3, 2025
1 parent e283827 commit 2a83b7f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const usage_text =
\\ --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
\\ -w, --warmup (default: false) runs each command once before mesuring
\\
;

Expand Down Expand Up @@ -92,6 +93,7 @@ pub fn main() !void {
var max_nano_seconds: u64 = std.time.ns_per_s * 5;
var color: ColorMode = .auto;
var allow_failures = false;
var warmup = false;

var arg_i: usize = 1;
while (arg_i < args.len) : (arg_i += 1) {
Expand Down Expand Up @@ -142,6 +144,8 @@ pub fn main() !void {
}
} else if (std.mem.eql(u8, arg, "-f") or std.mem.eql(u8, arg, "--allow-failures")) {
allow_failures = true;
} else if (std.mem.eql(u8, arg, "-w") or std.mem.eql(u8, arg, "--warmup")) {
warmup = true;
} else {
std.debug.print("unrecognized argument: '{s}'\n{s}", .{ arg, usage_text });
std.process.exit(1);
Expand Down Expand Up @@ -170,6 +174,24 @@ pub fn main() !void {
var timer = std.time.Timer.start() catch @panic("need timer to work");

for (commands.items, 1..) |*command, command_n| {
if (warmup) {
if (tty_conf != .no_color) try bar.render();

var child = std.process.Child.init(command.argv, arena);

child.stdin_behavior = .Ignore;
child.stdout_behavior = .Ignore;
child.stderr_behavior = .Ignore;
child.request_resource_usage_statistics = false;

try child.spawn();

_ = child.wait() catch |err| {
std.debug.print("\nerror: Couldn't execute {s}: {s}\n", .{ command.argv[0], @errorName(err) });
std.process.exit(1);
};
}

stderr_fba.reset();

const max_prog_name_len = 50;
Expand Down

0 comments on commit 2a83b7f

Please sign in to comment.