Created
May 27, 2022 15:14
-
-
Save matu3ba/c643b26b5e18a2aff20ef75468aa088d to your computer and use it in GitHub Desktop.
bench_childprocess.zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn main() !void { | |
try std.io.getStdOut().writer().writeAll("hello world\n"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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