Skip to content

Commit caa8ce4

Browse files
committed
Fix benchmarks build with Zig 0.15.1
1 parent a1e66de commit caa8ce4

File tree

2 files changed

+50
-14
lines changed

2 files changed

+50
-14
lines changed

build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const std = @import("std");
22

33
pub fn build(b: *std.Build) void {
44
const target = b.standardTargetOptions(.{});
5-
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
5+
const with_benchmark: bool = b.option(bool, "with-benchmark", "Compile benchmark") orelse false;
6+
const optimize = if (with_benchmark) .ReleaseFast else b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
67
const version = std.SemanticVersion.parse("0.4.1") catch unreachable;
78

89
const lib = b.addLibrary(.{
@@ -26,7 +27,6 @@ pub fn build(b: *std.Build) void {
2627
lib.root_module.addCMacro("FAVOR_PERFORMANCE", "1");
2728
}
2829

29-
const with_benchmark: bool = b.option(bool, "with-benchmark", "Compile benchmark") orelse false;
3030
lib_options.addOption(bool, "benchmark", with_benchmark);
3131

3232
lib.addIncludePath(b.path("src/include"));

src/test/benchmark.zig

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ fn bench_aegis256() !void {
3636
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
3737
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
3838
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
39-
const stdout = std.fs.File.stdout().deprecatedWriter();
39+
var stdout_buffer: [1024]u8 = undefined;
40+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
41+
const stdout = &stdout_writer.interface;
4042
try stdout.print("AEGIS-256\t{d:10.2} Mb/s\n", .{throughput});
43+
try stdout.flush();
4144
}
4245

4346
fn bench_aegis256x2() !void {
@@ -68,8 +71,11 @@ fn bench_aegis256x2() !void {
6871
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
6972
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
7073
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
71-
const stdout = std.fs.File.stdout().deprecatedWriter();
74+
var stdout_buffer: [1024]u8 = undefined;
75+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
76+
const stdout = &stdout_writer.interface;
7277
try stdout.print("AEGIS-256X2\t{d:10.2} Mb/s\n", .{throughput});
78+
try stdout.flush();
7379
}
7480

7581
fn bench_aegis256x4() !void {
@@ -100,8 +106,11 @@ fn bench_aegis256x4() !void {
100106
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
101107
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
102108
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
103-
const stdout = std.fs.File.stdout().deprecatedWriter();
109+
var stdout_buffer: [1024]u8 = undefined;
110+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
111+
const stdout = &stdout_writer.interface;
104112
try stdout.print("AEGIS-256X4\t{d:10.2} Mb/s\n", .{throughput});
113+
try stdout.flush();
105114
}
106115

107116
fn bench_aegis128l() !void {
@@ -132,8 +141,11 @@ fn bench_aegis128l() !void {
132141
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
133142
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
134143
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
135-
const stdout = std.fs.File.stdout().deprecatedWriter();
144+
var stdout_buffer: [1024]u8 = undefined;
145+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
146+
const stdout = &stdout_writer.interface;
136147
try stdout.print("AEGIS-128L\t{d:10.2} Mb/s\n", .{throughput});
148+
try stdout.flush();
137149
}
138150

139151
fn bench_aegis128x2() !void {
@@ -164,8 +176,11 @@ fn bench_aegis128x2() !void {
164176
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
165177
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
166178
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
167-
const stdout = std.fs.File.stdout().deprecatedWriter();
179+
var stdout_buffer: [1024]u8 = undefined;
180+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
181+
const stdout = &stdout_writer.interface;
168182
try stdout.print("AEGIS-128X2\t{d:10.2} Mb/s\n", .{throughput});
183+
try stdout.flush();
169184
}
170185

171186
fn bench_aegis128x4() !void {
@@ -196,8 +211,11 @@ fn bench_aegis128x4() !void {
196211
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
197212
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
198213
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
199-
const stdout = std.fs.File.stdout().deprecatedWriter();
214+
var stdout_buffer: [1024]u8 = undefined;
215+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
216+
const stdout = &stdout_writer.interface;
200217
try stdout.print("AEGIS-128X4\t{d:10.2} Mb/s\n", .{throughput});
218+
try stdout.flush();
201219
}
202220

203221
fn bench_aegis128l_mac() !void {
@@ -223,8 +241,11 @@ fn bench_aegis128l_mac() !void {
223241
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
224242
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
225243
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
226-
const stdout = std.fs.File.stdout().deprecatedWriter();
244+
var stdout_buffer: [1024]u8 = undefined;
245+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
246+
const stdout = &stdout_writer.interface;
227247
try stdout.print("AEGIS-128L MAC\t{d:10.2} Mb/s\n", .{throughput});
248+
try stdout.flush();
228249
}
229250

230251
fn bench_aegis128x2_mac() !void {
@@ -250,8 +271,11 @@ fn bench_aegis128x2_mac() !void {
250271
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
251272
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
252273
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
253-
const stdout = std.fs.File.stdout().deprecatedWriter();
274+
var stdout_buffer: [1024]u8 = undefined;
275+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
276+
const stdout = &stdout_writer.interface;
254277
try stdout.print("AEGIS-128X2 MAC\t{d:10.2} Mb/s\n", .{throughput});
278+
try stdout.flush();
255279
}
256280

257281
fn bench_aegis128x4_mac() !void {
@@ -278,8 +302,11 @@ fn bench_aegis128x4_mac() !void {
278302
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
279303
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
280304
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
281-
const stdout = std.fs.File.stdout().deprecatedWriter();
305+
var stdout_buffer: [1024]u8 = undefined;
306+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
307+
const stdout = &stdout_writer.interface;
282308
try stdout.print("AEGIS-128X4 MAC\t{d:10.2} Mb/s\n", .{throughput});
309+
try stdout.flush();
283310
}
284311

285312
fn bench_aegis256_mac() !void {
@@ -305,8 +332,11 @@ fn bench_aegis256_mac() !void {
305332
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
306333
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
307334
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
308-
const stdout = std.fs.File.stdout().deprecatedWriter();
335+
var stdout_buffer: [1024]u8 = undefined;
336+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
337+
const stdout = &stdout_writer.interface;
309338
try stdout.print("AEGIS-256 MAC\t{d:10.2} Mb/s\n", .{throughput});
339+
try stdout.flush();
310340
}
311341

312342
fn bench_aegis256x2_mac() !void {
@@ -333,8 +363,11 @@ fn bench_aegis256x2_mac() !void {
333363
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
334364
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
335365
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
336-
const stdout = std.fs.File.stdout().deprecatedWriter();
366+
var stdout_buffer: [1024]u8 = undefined;
367+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
368+
const stdout = &stdout_writer.interface;
337369
try stdout.print("AEGIS-256X2 MAC\t{d:10.2} Mb/s\n", .{throughput});
370+
try stdout.flush();
338371
}
339372

340373
fn bench_aegis256x4_mac() !void {
@@ -361,8 +394,11 @@ fn bench_aegis256x4_mac() !void {
361394
const bits: f128 = @floatFromInt(@as(u128, msg_len) * iterations * 8);
362395
const elapsed_s = @as(f128, @floatFromInt(end - start)) / time.ns_per_s;
363396
const throughput = @as(f64, @floatCast(bits / (elapsed_s * 1000 * 1000)));
364-
const stdout = std.fs.File.stdout().deprecatedWriter();
397+
var stdout_buffer: [1024]u8 = undefined;
398+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
399+
const stdout = &stdout_writer.interface;
365400
try stdout.print("AEGIS-256X4 MAC\t{d:10.2} Mb/s\n", .{throughput});
401+
try stdout.flush();
366402
}
367403

368404
pub fn main() !void {

0 commit comments

Comments
 (0)