| ... | ... | @@ -7,6 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const builtin = @import("builtin"); |
| 9 | 9 | const std = @import("std"); |
| 10 | const mem = std.mem; |
| 10 | 11 | const time = std.time; |
| 11 | 12 | const Timer = time.Timer; |
| 12 | 13 | const crypto = std.crypto; |
| ... | ... | @@ -21,14 +22,6 @@ const Crypto = struct { |
| 21 | 22 | name: []const u8, |
| 22 | 23 | }; |
| 23 | 24 | |
| 24 | | fn blackBox(x: anytype) void { |
| 25 | | asm volatile ("" |
| 26 | | : |
| 27 | | : [x] "rm" (x) |
| 28 | | : "memory" |
| 29 | | ); |
| 30 | | } |
| 31 | | |
| 32 | 25 | const hashes = [_]Crypto{ |
| 33 | 26 | Crypto{ .ty = crypto.hash.Md5, .name = "md5" }, |
| 34 | 27 | Crypto{ .ty = crypto.hash.Sha1, .name = "sha1" }, |
| ... | ... | @@ -54,7 +47,7 @@ pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64 |
| 54 | 47 | while (offset < bytes) : (offset += block.len) { |
| 55 | 48 | h.update(block[0..]); |
| 56 | 49 | } |
| 57 | | blackBox(&h); |
| 50 | mem.forceEval(&h); |
| 58 | 51 | const end = timer.read(); |
| 59 | 52 | |
| 60 | 53 | const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s; |
| ... | ... | @@ -89,7 +82,7 @@ pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 { |
| 89 | 82 | const start = timer.lap(); |
| 90 | 83 | while (offset < bytes) : (offset += in.len) { |
| 91 | 84 | Mac.create(mac[0..], in[0..], key[0..]); |
| 92 | | blackBox(&mac); |
| 85 | mem.forceEval(&mac); |
| 93 | 86 | } |
| 94 | 87 | const end = timer.read(); |
| 95 | 88 | |
| ... | ... | @@ -116,7 +109,7 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c |
| 116 | 109 | var i: usize = 0; |
| 117 | 110 | while (i < exchange_count) : (i += 1) { |
| 118 | 111 | _ = DhKeyExchange.create(out[0..], out[0..], in[0..]); |
| 119 | | blackBox(&out); |
| 112 | mem.forceEval(&out); |
| 120 | 113 | } |
| 121 | 114 | } |
| 122 | 115 | const end = timer.read(); |
| ... | ... | @@ -141,7 +134,7 @@ pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count |
| 141 | 134 | var i: usize = 0; |
| 142 | 135 | while (i < signatures_count) : (i += 1) { |
| 143 | 136 | const s = try Signature.sign(&msg, key_pair, null); |
| 144 | | blackBox(&s); |
| 137 | mem.forceEval(&s); |
| 145 | 138 | } |
| 146 | 139 | } |
| 147 | 140 | const end = timer.read(); |
| ... | ... | @@ -177,7 +170,7 @@ pub fn benchmarkAead(comptime Aead: anytype, comptime bytes: comptime_int) !u64 |
| 177 | 170 | Aead.encrypt(in[0..], tag[0..], in[0..], &[_]u8{}, nonce, key); |
| 178 | 171 | Aead.decrypt(in[0..], in[0..], tag, &[_]u8{}, nonce, key) catch unreachable; |
| 179 | 172 | } |
| 180 | | blackBox(&in); |
| 173 | mem.forceEval(&in); |
| 181 | 174 | const end = timer.read(); |
| 182 | 175 | |
| 183 | 176 | const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s; |