| ... | @@ -90,7 +90,6 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c | ... | @@ -90,7 +90,6 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c |
| 90 | var out: [DhKeyExchange.minimum_key_length]u8 = undefined; | 90 | var out: [DhKeyExchange.minimum_key_length]u8 = undefined; |
| 91 | prng.random.bytes(out[0..]); | 91 | prng.random.bytes(out[0..]); |
| 92 | | 92 | |
| 93 | var offset: usize = 0; | | |
| 94 | var timer = try Timer.start(); | 93 | var timer = try Timer.start(); |
| 95 | const start = timer.lap(); | 94 | const start = timer.lap(); |
| 96 | { | 95 | { |
| ... | @@ -107,6 +106,30 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c | ... | @@ -107,6 +106,30 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c |
| 107 | return throughput; | 106 | return throughput; |
| 108 | } | 107 | } |
| 109 | | 108 | |
| | 109 | const signatures = [_]Crypto{Crypto{ .ty = crypto.Ed25519, .name = "ed25519" }}; |
| | 110 | |
| | 111 | pub fn benchmarkSignatures(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 { |
| | 112 | var seed: [Signature.seed_length]u8 = undefined; |
| | 113 | prng.random.bytes(seed[0..]); |
| | 114 | const msg = [_]u8{0} ** 64; |
| | 115 | const key_pair = try Signature.createKeyPair(seed); |
| | 116 | |
| | 117 | var timer = try Timer.start(); |
| | 118 | const start = timer.lap(); |
| | 119 | { |
| | 120 | var i: usize = 0; |
| | 121 | while (i < signatures_count) : (i += 1) { |
| | 122 | _ = try Signature.sign(&msg, key_pair, null); |
| | 123 | } |
| | 124 | } |
| | 125 | const end = timer.read(); |
| | 126 | |
| | 127 | const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s; |
| | 128 | const throughput = @floatToInt(u64, signatures_count / elapsed_s); |
| | 129 | |
| | 130 | return throughput; |
| | 131 | } |
| | 132 | |
| 110 | fn usage() void { | 133 | fn usage() void { |
| 111 | std.debug.warn( | 134 | std.debug.warn( |
| 112 | \\throughput_test [options] | 135 | \\throughput_test [options] |
| ... | @@ -183,4 +206,11 @@ pub fn main() !void { | ... | @@ -183,4 +206,11 @@ pub fn main() !void { |
| 183 | try stdout.print("{:>11}: {:5} exchanges/s\n", .{ E.name, throughput }); | 206 | try stdout.print("{:>11}: {:5} exchanges/s\n", .{ E.name, throughput }); |
| 184 | } | 207 | } |
| 185 | } | 208 | } |
| | 209 | |
| | 210 | inline for (signatures) |E| { |
| | 211 | if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) { |
| | 212 | const throughput = try benchmarkSignatures(E.ty, mode(1000)); |
| | 213 | try stdout.print("{:>11}: {:5} signatures/s\n", .{ E.name, throughput }); |
| | 214 | } |
| | 215 | } |
| 186 | } | 216 | } |