Compare commits

..

No commits in common. "main" and "0.1.1" have entirely different histories.
main ... 0.1.1

View File

@ -161,6 +161,7 @@ fn bench_vsNative(writer: *std.Io.Writer) !void {
const ITERS: usize = 100_000; const ITERS: usize = 100_000;
const SAMPLES: usize = 5; const SAMPLES: usize = 5;
// Helper to safely get a value of type T from a loop index
const getValT = struct { const getValT = struct {
fn f(comptime TT: type, i: usize) TT { fn f(comptime TT: type, i: usize) TT {
const v = (i % 100) + 1; const v = (i % 100) + 1;
@ -170,8 +171,7 @@ fn bench_vsNative(writer: *std.Io.Writer) !void {
const Types = .{ i32, i64, i128, f32, f64 }; const Types = .{ i32, i64, i128, f32, f64 };
const TNames = .{ "i32", "i64", "i128", "f32", "f64" }; const TNames = .{ "i32", "i64", "i128", "f32", "f64" };
// Expanded Ops to match bench_Scalar const Ops = .{ "add", "mul", "div" };
const Ops = .{ "add", "sub", "mul", "div", "abs", "eq", "gt" };
try writer.print( try writer.print(
\\ \\
@ -198,24 +198,11 @@ fn bench_vsNative(writer: *std.Io.Writer) !void {
for (0..ITERS) |i| { for (0..ITERS) |i| {
const a = getValT(T, i); const a = getValT(T, i);
const b = getValT(T, 2); const b = getValT(T, 2);
// Native logic branch
_ = if (comptime std.mem.eql(u8, op_name, "add")) _ = if (comptime std.mem.eql(u8, op_name, "add"))
a + b a + b
else if (comptime std.mem.eql(u8, op_name, "sub"))
a - b
else if (comptime std.mem.eql(u8, op_name, "mul")) else if (comptime std.mem.eql(u8, op_name, "mul"))
a * b a * b
else if (comptime std.mem.eql(u8, op_name, "div")) else if (comptime @typeInfo(T) == .int) @divTrunc(a, b) else a / b;
if (comptime @typeInfo(T) == .int) @divTrunc(a, b) else a / b
else if (comptime std.mem.eql(u8, op_name, "abs"))
if (comptime @typeInfo(T) == .int) @abs(a) else @as(T, @abs(a))
else if (comptime std.mem.eql(u8, op_name, "eq"))
a == b
else if (comptime std.mem.eql(u8, op_name, "gt"))
a > b
else
unreachable;
} }
const n_end = getTime(); const n_end = getTime();
native_total_ns += @as(f64, @floatFromInt(n_start.durationTo(n_end).toNanoseconds())); native_total_ns += @as(f64, @floatFromInt(n_start.durationTo(n_end).toNanoseconds()));
@ -226,23 +213,12 @@ fn bench_vsNative(writer: *std.Io.Writer) !void {
const qa = M{ .value = getValT(T, i) }; const qa = M{ .value = getValT(T, i) };
const qb = if (comptime std.mem.eql(u8, op_name, "div")) S{ .value = getValT(T, 2) } else M{ .value = getValT(T, 2) }; const qb = if (comptime std.mem.eql(u8, op_name, "div")) S{ .value = getValT(T, 2) } else M{ .value = getValT(T, 2) };
// Scalar logic branch
_ = if (comptime std.mem.eql(u8, op_name, "add")) _ = if (comptime std.mem.eql(u8, op_name, "add"))
qa.add(qb) qa.add(qb)
else if (comptime std.mem.eql(u8, op_name, "sub"))
qa.sub(qb)
else if (comptime std.mem.eql(u8, op_name, "mul")) else if (comptime std.mem.eql(u8, op_name, "mul"))
qa.mul(qb) qa.mul(qb)
else if (comptime std.mem.eql(u8, op_name, "div"))
qa.div(qb)
else if (comptime std.mem.eql(u8, op_name, "abs"))
qa.abs()
else if (comptime std.mem.eql(u8, op_name, "eq"))
qa.eq(qb)
else if (comptime std.mem.eql(u8, op_name, "gt"))
qa.gt(qb)
else else
unreachable; qa.div(qb);
} }
const q_end = getTime(); const q_end = getTime();
quantity_total_ns += @as(f64, @floatFromInt(q_start.durationTo(q_end).toNanoseconds())); quantity_total_ns += @as(f64, @floatFromInt(q_start.durationTo(q_end).toNanoseconds()));