Skip to content

Commit

Permalink
bench: make aio/coro _nops similar
Browse files Browse the repository at this point in the history
use the same batch size, avoid inlining the loops in aio
  • Loading branch information
Cloudef committed Feb 1, 2025
1 parent 160b765 commit 773682e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions bench/aio_nops.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ pub const std_options: std.Options = .{

const TOTAL_NOPS = 2_500_000_00;

fn nopLoop(io: *aio.Dynamic, total: usize) !void {
var i: usize = 0;
while (i < total) {
const batch = 32;
try io.queue(.{aio.op(.nop, .{}, .unlinked)} ** batch, {});
const res = try io.complete(.blocking, {});
i += res.num_completed;
}
}

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
Expand All @@ -18,15 +28,10 @@ pub fn main() !void {
var io = try aio.Dynamic.init(allocator, queue_size);
defer io.deinit(allocator);

var total: usize = TOTAL_NOPS;
std.mem.doNotOptimizeAway(&total);
const start_time = try std.time.Instant.now();
var i: usize = 0;
while (i < TOTAL_NOPS) {
for (0..queue_size) |_| {
try io.queue(aio.op(.nop, .{}, .unlinked), {});
}
const res = try io.complete(.blocking, {});
i += res.num_completed;
}
try nopLoop(&io, total);
const end_time = try std.time.Instant.now();

const elapsed: f64 = @floatFromInt(end_time.since(start_time));
Expand Down
6 changes: 3 additions & 3 deletions bench/coro_nops.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const TOTAL_NOPS = 2_500_000_00;
fn nopLoop(total: usize) !void {
var i: usize = 0;
while (i < total) {
const chunk = 32;
try coro.io.multi(.{aio.op(.nop, .{}, .unlinked)} ** chunk);
i += chunk;
const batch = 32;
try coro.io.multi(.{aio.op(.nop, .{}, .unlinked)} ** batch);
i += batch;
}
}

Expand Down

0 comments on commit 773682e

Please sign in to comment.