Skip to content

Instantly share code, notes, and snippets.

@matu3ba
Created May 27, 2022 15:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save matu3ba/c643b26b5e18a2aff20ef75468aa088d to your computer and use it in GitHub Desktop.
bench_childprocess.zig
const std = @import("std");
pub fn main() !void {
try std.io.getStdOut().writer().writeAll("hello world\n");
}
const std = @import("std");
const ChildProcess = std.ChildProcess;
const testing = std.testing;
pub fn main() !void {
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(!general_purpose_allocator.deinit());
const gpa = general_purpose_allocator.allocator();
var child_proceses: [1_000]ChildProcess = undefined;
for (child_proceses) |*child_process| {
child_process.* = ChildProcess.init(
&[_][]const u8{"./child"},
gpa,
);
}
for (child_proceses) |*child_process| {
//try child_process.spawn(null);
try child_process.spawn();
}
for (child_proceses) |*child_process| {
const ret_val = try child_process.wait();
try testing.expectEqual(ret_val, .{ .Exited = 0 });
}
}
zig build-exe -OReleaseFast parent.zig
zig build-exe -OReleaseFast child.zig
time ./parent
round about these values, if repeated sufficiently often:
real 0m0,263s
user 0m0,483s
sys 0m0,332s
With the changes applies (null inserted into spawn function):
real 0m0,255s
user 0m0,471s
sys 0m0,327s
Next: trying to simulate some work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment