@@ -3,7 +3,7 @@ const std = @import("std");
33const Io = std .Io ;
44const mem = std .mem ;
55const time = std .time ;
6- const Timer = std .time . Timer ;
6+ const Timestamp = std .Io . Timestamp ;
77
88const msg_len : usize = 16384 ;
99const iterations = 100000 ;
@@ -17,8 +17,7 @@ fn bench_aegis256(io: Io, stdout: *Io.Writer) !void {
1717 io .random (& nonce );
1818 io .random (& buf );
1919
20- var timer = try Timer .start ();
21- const start = timer .lap ();
20+ const start = Timestamp .now (io , .awake );
2221 for (0.. iterations ) | _ | {
2322 _ = aegis .aegis256_encrypt (
2423 & buf ,
@@ -31,10 +30,10 @@ fn bench_aegis256(io: Io, stdout: *Io.Writer) !void {
3130 & key ,
3231 );
3332 }
34- const end = timer . read ( );
33+ const end = Timestamp . now ( io , .awake );
3534 mem .doNotOptimizeAway (buf [0 ]);
3635 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
37- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
36+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
3837 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
3938 try stdout .print ("AEGIS-256\t {d:10.2} Mb/s\n " , .{throughput });
4039}
@@ -48,8 +47,7 @@ fn bench_aegis256x2(io: Io, stdout: *Io.Writer) !void {
4847 io .random (& nonce );
4948 io .random (& buf );
5049
51- var timer = try Timer .start ();
52- const start = timer .lap ();
50+ const start = Timestamp .now (io , .awake );
5351 for (0.. iterations ) | _ | {
5452 _ = aegis .aegis256x2_encrypt (
5553 & buf ,
@@ -62,10 +60,10 @@ fn bench_aegis256x2(io: Io, stdout: *Io.Writer) !void {
6260 & key ,
6361 );
6462 }
65- const end = timer . read ( );
63+ const end = Timestamp . now ( io , .awake );
6664 mem .doNotOptimizeAway (buf [0 ]);
6765 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
68- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
66+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
6967 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
7068 try stdout .print ("AEGIS-256X2\t {d:10.2} Mb/s\n " , .{throughput });
7169}
@@ -79,8 +77,7 @@ fn bench_aegis256x4(io: Io, stdout: *Io.Writer) !void {
7977 io .random (& nonce );
8078 io .random (& buf );
8179
82- var timer = try Timer .start ();
83- const start = timer .lap ();
80+ const start = Timestamp .now (io , .awake );
8481 for (0.. iterations ) | _ | {
8582 _ = aegis .aegis256x4_encrypt (
8683 & buf ,
@@ -93,10 +90,10 @@ fn bench_aegis256x4(io: Io, stdout: *Io.Writer) !void {
9390 & key ,
9491 );
9592 }
96- const end = timer . read ( );
93+ const end = Timestamp . now ( io , .awake );
9794 mem .doNotOptimizeAway (buf [0 ]);
9895 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
99- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
96+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
10097 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
10198 try stdout .print ("AEGIS-256X4\t {d:10.2} Mb/s\n " , .{throughput });
10299}
@@ -110,8 +107,7 @@ fn bench_aegis128l(io: Io, stdout: *Io.Writer) !void {
110107 io .random (& nonce );
111108 io .random (& buf );
112109
113- var timer = try Timer .start ();
114- const start = timer .lap ();
110+ const start = Timestamp .now (io , .awake );
115111 for (0.. iterations ) | _ | {
116112 _ = aegis .aegis128l_encrypt (
117113 & buf ,
@@ -124,10 +120,10 @@ fn bench_aegis128l(io: Io, stdout: *Io.Writer) !void {
124120 & key ,
125121 );
126122 }
127- const end = timer . read ( );
123+ const end = Timestamp . now ( io , .awake );
128124 mem .doNotOptimizeAway (buf [0 ]);
129125 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
130- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
126+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
131127 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
132128 try stdout .print ("AEGIS-128L\t {d:10.2} Mb/s\n " , .{throughput });
133129}
@@ -141,8 +137,7 @@ fn bench_aegis128x2(io: Io, stdout: *Io.Writer) !void {
141137 io .random (& nonce );
142138 io .random (& buf );
143139
144- var timer = try Timer .start ();
145- const start = timer .lap ();
140+ const start = Timestamp .now (io , .awake );
146141 for (0.. iterations ) | _ | {
147142 _ = aegis .aegis128x2_encrypt (
148143 & buf ,
@@ -155,10 +150,10 @@ fn bench_aegis128x2(io: Io, stdout: *Io.Writer) !void {
155150 & key ,
156151 );
157152 }
158- const end = timer . read ( );
153+ const end = Timestamp . now ( io , .awake );
159154 mem .doNotOptimizeAway (buf [0 ]);
160155 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
161- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
156+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
162157 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
163158 try stdout .print ("AEGIS-128X2\t {d:10.2} Mb/s\n " , .{throughput });
164159}
@@ -172,8 +167,7 @@ fn bench_aegis128x4(io: Io, stdout: *Io.Writer) !void {
172167 io .random (& nonce );
173168 io .random (& buf );
174169
175- var timer = try Timer .start ();
176- const start = timer .lap ();
170+ const start = Timestamp .now (io , .awake );
177171 for (0.. iterations ) | _ | {
178172 _ = aegis .aegis128x4_encrypt (
179173 & buf ,
@@ -186,10 +180,10 @@ fn bench_aegis128x4(io: Io, stdout: *Io.Writer) !void {
186180 & key ,
187181 );
188182 }
189- const end = timer . read ( );
183+ const end = Timestamp . now ( io , .awake );
190184 mem .doNotOptimizeAway (buf [0 ]);
191185 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
192- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
186+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
193187 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
194188 try stdout .print ("AEGIS-128X4\t {d:10.2} Mb/s\n " , .{throughput });
195189}
@@ -205,17 +199,16 @@ fn bench_aegis128l_mac(io: Io, stdout: *Io.Writer) !void {
205199 io .random (& buf );
206200 aegis .aegis128l_mac_init (& st , & key , & nonce );
207201
208- var timer = try Timer .start ();
209- const start = timer .lap ();
202+ const start = Timestamp .now (io , .awake );
210203 for (0.. iterations ) | _ | {
211204 aegis .aegis128l_mac_reset (& st );
212205 _ = aegis .aegis128l_mac_update (& st , & buf , msg_len );
213206 _ = aegis .aegis128l_mac_final (& st , & buf , aegis .aegis128l_ABYTES_MAX );
214207 }
215- const end = timer . read ( );
208+ const end = Timestamp . now ( io , .awake );
216209 mem .doNotOptimizeAway (buf [0 ]);
217210 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
218- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
211+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
219212 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
220213 try stdout .print ("AEGIS-128L MAC\t {d:10.2} Mb/s\n " , .{throughput });
221214}
@@ -231,17 +224,16 @@ fn bench_aegis128x2_mac(io: Io, stdout: *Io.Writer) !void {
231224 io .random (& buf );
232225 aegis .aegis128x2_mac_init (& st , & key , & nonce );
233226
234- var timer = try Timer .start ();
235- const start = timer .lap ();
227+ const start = Timestamp .now (io , .awake );
236228 for (0.. iterations ) | _ | {
237229 aegis .aegis128x2_mac_reset (& st );
238230 _ = aegis .aegis128x2_mac_update (& st , & buf , msg_len );
239231 _ = aegis .aegis128x2_mac_final (& st , & buf , aegis .aegis128x2_ABYTES_MAX );
240232 }
241- const end = timer . read ( );
233+ const end = Timestamp . now ( io , .awake );
242234 mem .doNotOptimizeAway (buf [0 ]);
243235 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
244- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
236+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
245237 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
246238 try stdout .print ("AEGIS-128X2 MAC\t {d:10.2} Mb/s\n " , .{throughput });
247239}
@@ -257,18 +249,17 @@ fn bench_aegis128x4_mac(io: Io, stdout: *Io.Writer) !void {
257249 io .random (& buf );
258250 aegis .aegis128x4_mac_init (& st0 , & key , & nonce );
259251
260- var timer = try Timer .start ();
261- const start = timer .lap ();
252+ const start = Timestamp .now (io , .awake );
262253 for (0.. iterations ) | _ | {
263254 var st : aegis .aegis128x4_mac_state align (64 ) = undefined ;
264255 aegis .aegis128x4_mac_state_clone (& st , & st0 );
265256 _ = aegis .aegis128x4_mac_update (& st , & buf , msg_len );
266257 _ = aegis .aegis128x4_mac_final (& st , & buf , aegis .aegis128x4_ABYTES_MAX );
267258 }
268- const end = timer . read ( );
259+ const end = Timestamp . now ( io , .awake );
269260 mem .doNotOptimizeAway (buf [0 ]);
270261 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
271- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
262+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
272263 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
273264 try stdout .print ("AEGIS-128X4 MAC\t {d:10.2} Mb/s\n " , .{throughput });
274265}
@@ -284,17 +275,16 @@ fn bench_aegis256_mac(io: Io, stdout: *Io.Writer) !void {
284275 io .random (& buf );
285276 aegis .aegis256_mac_init (& st , & key , & nonce );
286277
287- var timer = try Timer .start ();
288- const start = timer .lap ();
278+ const start = Timestamp .now (io , .awake );
289279 for (0.. iterations ) | _ | {
290280 aegis .aegis256_mac_reset (& st );
291281 _ = aegis .aegis256_mac_update (& st , & buf , msg_len );
292282 _ = aegis .aegis256_mac_final (& st , & buf , aegis .aegis256_ABYTES_MAX );
293283 }
294- const end = timer . read ( );
284+ const end = Timestamp . now ( io , .awake );
295285 mem .doNotOptimizeAway (buf [0 ]);
296286 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
297- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
287+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
298288 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
299289 try stdout .print ("AEGIS-256 MAC\t {d:10.2} Mb/s\n " , .{throughput });
300290}
@@ -310,18 +300,17 @@ fn bench_aegis256x2_mac(io: Io, stdout: *Io.Writer) !void {
310300 io .random (& buf );
311301 aegis .aegis256x2_mac_init (& st0 , & key , & nonce );
312302
313- var timer = try Timer .start ();
314- const start = timer .lap ();
303+ const start = Timestamp .now (io , .awake );
315304 for (0.. iterations ) | _ | {
316305 var st : aegis .aegis256x2_mac_state align (32 ) = undefined ;
317306 aegis .aegis256x2_mac_state_clone (& st , & st0 );
318307 _ = aegis .aegis256x2_mac_update (& st , & buf , msg_len );
319308 _ = aegis .aegis256x2_mac_final (& st , & buf , aegis .aegis256x2_ABYTES_MAX );
320309 }
321- const end = timer . read ( );
310+ const end = Timestamp . now ( io , .awake );
322311 mem .doNotOptimizeAway (buf [0 ]);
323312 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
324- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
313+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
325314 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
326315 try stdout .print ("AEGIS-256X2 MAC\t {d:10.2} Mb/s\n " , .{throughput });
327316}
@@ -337,18 +326,17 @@ fn bench_aegis256x4_mac(io: Io, stdout: *Io.Writer) !void {
337326 io .random (& buf );
338327 aegis .aegis256x4_mac_init (& st0 , & key , & nonce );
339328
340- var timer = try Timer .start ();
341- const start = timer .lap ();
329+ const start = Timestamp .now (io , .awake );
342330 for (0.. iterations ) | _ | {
343331 var st : aegis .aegis256x4_mac_state align (64 ) = undefined ;
344332 aegis .aegis256x4_mac_state_clone (& st , & st0 );
345333 _ = aegis .aegis256x4_mac_update (& st , & buf , msg_len );
346334 _ = aegis .aegis256x4_mac_final (& st , & buf , aegis .aegis256x4_ABYTES_MAX );
347335 }
348- const end = timer . read ( );
336+ const end = Timestamp . now ( io , .awake );
349337 mem .doNotOptimizeAway (buf [0 ]);
350338 const bits : f128 = @floatFromInt (@as (u128 , msg_len ) * iterations * 8 );
351- const elapsed_s = @as (f128 , @floatFromInt (end - start )) / time .ns_per_s ;
339+ const elapsed_s = @as (f128 , @floatFromInt (end . nanoseconds - start . nanoseconds )) / time .ns_per_s ;
352340 const throughput = @as (f64 , @floatCast (bits / (elapsed_s * 1000 * 1000 )));
353341 try stdout .print ("AEGIS-256X4 MAC\t {d:10.2} Mb/s\n " , .{throughput });
354342}
0 commit comments