XKMEZUFTLVXL65G6JWQQ6I7HRDHZDUSM3KQQVZ6RVIKOW2OLUKBAC
LVNADDHM446QNUHG3VTNBOHNJGCDROOFBVGO4WXMUUAN6Y4LNCNAC
P7OMU7PBSC76C6FLDU3TT6ZRSKMNRTYAA4IM65ICVIHSMNUQWRBAC
UAUV6SYV72FWMQVALN5YFTANLHIG6B5JHTZLJJUN5SN7SALYAC3AC
5WBYLJAC3MP52G4F5KHVTXOGCBYS7RFACMFQEAAA2D2TON4OBAGQC
2HKNCI4IG65FEWNSRBJ5SESMN4STJ6WSCNODP3UK6LBQMDHYPNTAC
GJA75BA6ZNFQL6DG7YSRQKJWGX52YJKL3DZO3OWO6D4HVH6JS7NQC
VDX2MMS55XMEHH2TEMOOW225K6NGKB4QXPQFQ2WJLVXJK25BSXMQC
NKL44S6YUCLZDH5EDDUJB5BHX2QWDP7SI5RROBVAUXKAU4ADKPAQC
7G5Y53RBBKF4QDPTVC2MFG45XHDOLEFPHA4XQIPJNW4RXCULMRQQC
XJHUBLK673LN2VVQ5FIOENXMS5OFSFWXM5GSP2X7XEVOL74WV6OAC
fn benchLazyXev() !void {
const xev = @import("xev");
var sl = try SL.init(std.heap.page_allocator);
defer sl.deinit();
var rand = std.rand.DefaultPrng.init(@intCast(std.time.milliTimestamp()));
const rnd = rand.random();
var pool = xev.ThreadPool.init(xev.ThreadPool.Config{});
defer {
pool.shutdown();
pool.deinit();
}
const wg = std.Thread.WaitGroup{};
for (0..BENCH_ITEMS) |_| {
// const key = rnd.intRangeAtMostBiased(BENCH_KEY, std.math.minInt(BENCH_KEY), BENCH_ITEMS / 20);
const query_type = rnd.intRangeAtMostBiased(u8, 0, 99);
switch (query_type) {
0 => { // 1% remove
// pool.spawnWg(&wg, Functions.remove, .{ sl, key });
},
1...9 => { // 9% insert
// pool.spawnWg(&wg, Functions.insert, .{ sl, key, {} });
},
else => { // 90% search
const task = xev.ThreadPool.Task{
.callback = struct {
fn callback(_: *xev.ThreadPool.Task) void {
defer wg.finish();
// _ = sl.search(key);
}
}.callback,
};
const batch = xev.ThreadPool.Batch.from(task);
wg.start();
xev.ThreadPool.schedule(batch);
},
}
}
var timer = try std.time.Timer.start();
wg.wait();
std.debug.print("Lazy {d} threads: {d} ms\n", .{
try std.Thread.getCpuCount(),
timer.read() / std.time.ns_per_ms,
});
}
fn benchXev() !void {
const xev = @import("xev").IO_Uring;
var rand = std.rand.DefaultPrng.init(@intCast(std.time.milliTimestamp()));
const rnd = rand.random();
const Callbacks = struct {
fn search(
sl: ?*SL,
_: *xev.Loop,
c: *xev.Completion,
result: xev.Timer.RunError!void,
) xev.CallbackAction {
_ = result catch unreachable;
const key: usize = @intFromPtr(c.userdata);
_ = sl.?.search(key);
std.log.debug("searched for {d}", .{c.userdata.?});
return .disarm;
}
};
var sl = try SL.init(std.heap.page_allocator);
defer sl.deinit();
var loop = try xev.Loop.init(xev.Options{});
defer loop.deinit();
var keys = try std.ArrayList(usize).initCapacity(std.heap.page_allocator, BENCH_ITEMS);
var comps = try std.ArrayList(xev.Completion).initCapacity(std.heap.page_allocator, BENCH_ITEMS);
for (0..BENCH_ITEMS) |i| {
const key = rnd.intRangeAtMostBiased(BENCH_KEY, std.math.minInt(BENCH_KEY), BENCH_ITEMS / 20);
keys.appendAssumeCapacity(key);
const query_type = rnd.intRangeAtMostBiased(u8, 0, 99);
switch (query_type) {
0 => { // 1% remove
// pool.spawnWg(&wg, Functions.remove, .{ sl, key });
},
1...9 => { // 9% insert
// pool.spawnWg(&wg, Functions.insert, .{ sl, key, {} });
},
else => { // 90% search
comps.appendAssumeCapacity(xev.Completion{
.userdata = &keys.items[i],
});
var timer = try xev.Timer.init();
defer timer.deinit();
timer.run(&loop, &comps.items[i], 0, SL, &sl, Callbacks.search);
},
}
}
try loop.run(.until_done);
}