Skip to content

Commit

Permalink
Nops (#77)
Browse files Browse the repository at this point in the history
bench: add coro_nops benchmark
  • Loading branch information
mrjbq7 authored Jan 31, 2025
1 parent 4f7c19c commit 1cbcd34
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions bench/coro_nops.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const std = @import("std");
const aio = @import("aio");
const coro = @import("coro");
const log = std.log.scoped(.coro_nops);

pub const std_options: std.Options = .{
.log_level = .debug,
};

const TOTAL_NOPS = 2_500_000;

fn nopLoop(total: usize) !void {
var i: usize = 0;
while (i < total) {
try coro.io.single(.nop, .{});
i += 1;
}
}

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();

const allocator = gpa.allocator();

var scheduler = try coro.Scheduler.init(allocator, .{});
defer scheduler.deinit();

_ = try scheduler.spawn(nopLoop, .{TOTAL_NOPS}, .{});

const start_time = try std.time.Instant.now();
try scheduler.run(.wait);
const end_time = try std.time.Instant.now();

const elapsed: f64 = @floatFromInt(end_time.since(start_time));
const nops_s: f64 = @as(f64, @floatFromInt(TOTAL_NOPS)) / (elapsed / 1e9);
log.info("{d:.2} nops/s", .{nops_s});
log.info("{d:.2} seconds total", .{elapsed / 1e9});
}
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub fn build(b: *std.Build) void {
.ping_pongs,
.ticker,
.flow,
.coro_nops,
}) |bench| {
const exe = b.addExecutable(.{
.name = @tagName(bench),
Expand Down

0 comments on commit 1cbcd34

Please sign in to comment.