aboutsummaryrefslogtreecommitdiff
path: root/lib/std/crypto/benchmark.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-08-16 22:35:39 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-08-16 22:35:39 -0700
commitaddeff889a1017beeef8c710dfdd55dbda2449e3 (patch)
tree36beac5edb4683d4b14bd395addcf55f846e315d /lib/std/crypto/benchmark.zig
parentf46e375bbe0ac0893717bd477eab78f51863e277 (diff)
parent7f9a227abfbce0e67746cc57dd9b6a4bf0a8d94a (diff)
downloadzig-addeff889a1017beeef8c710dfdd55dbda2449e3.tar.gz
zig-addeff889a1017beeef8c710dfdd55dbda2449e3.zip
Merge branch 'jedisct1-25519'
closes #6050
Diffstat (limited to 'lib/std/crypto/benchmark.zig')
-rw-r--r--lib/std/crypto/benchmark.zig32
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/std/crypto/benchmark.zig b/lib/std/crypto/benchmark.zig
index f0f40bd231..267c2881b4 100644
--- a/lib/std/crypto/benchmark.zig
+++ b/lib/std/crypto/benchmark.zig
@@ -90,7 +90,6 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
var out: [DhKeyExchange.minimum_key_length]u8 = undefined;
prng.random.bytes(out[0..]);
- var offset: usize = 0;
var timer = try Timer.start();
const start = timer.lap();
{
@@ -107,6 +106,30 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
return throughput;
}
+const signatures = [_]Crypto{Crypto{ .ty = crypto.Ed25519, .name = "ed25519" }};
+
+pub fn benchmarkSignatures(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 {
+ var seed: [Signature.seed_length]u8 = undefined;
+ prng.random.bytes(seed[0..]);
+ const msg = [_]u8{0} ** 64;
+ const key_pair = try Signature.createKeyPair(seed);
+
+ var timer = try Timer.start();
+ const start = timer.lap();
+ {
+ var i: usize = 0;
+ while (i < signatures_count) : (i += 1) {
+ _ = try Signature.sign(&msg, key_pair, null);
+ }
+ }
+ const end = timer.read();
+
+ const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s;
+ const throughput = @floatToInt(u64, signatures_count / elapsed_s);
+
+ return throughput;
+}
+
fn usage() void {
std.debug.warn(
\\throughput_test [options]
@@ -183,4 +206,11 @@ pub fn main() !void {
try stdout.print("{:>11}: {:5} exchanges/s\n", .{ E.name, throughput });
}
}
+
+ inline for (signatures) |E| {
+ if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {
+ const throughput = try benchmarkSignatures(E.ty, mode(1000));
+ try stdout.print("{:>11}: {:5} signatures/s\n", .{ E.name, throughput });
+ }
+ }
}