Skip to content

Instantly share code, notes, and snippets.

@tiehuis
Created August 30, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiehuis/185c975c4c07e465ab72c68abf11948a to your computer and use it in GitHub Desktop.
Save tiehuis/185c975c4c07e465ab72c68abf11948a to your computer and use it in GitHub Desktop.
poly1305/x25519 benchmark scripts
const std = @import("std");
const time = std.os.time;
const Timer = time.Timer;
const poly1305 = @import("poly1305.zig");
const MiB = 1024 * 1024;
const BytesToHash = 128 * MiB;
pub fn main() !void {
var stdout_file = try std.io.getStdOut();
var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
const stdout = &stdout_out_stream.stream;
var out: [16]u8 = undefined;
var prng = std.rand.DefaultPrng.init(0);
var in = try std.heap.c_allocator.alloc(u8, BytesToHash);
prng.random.bytes(in);
var key: [32]u8 = undefined;
prng.random.bytes(key[0..]);
var timer = try Timer.start();
const start = timer.lap();
_ = poly1305.crypto_poly1305(out[0..], in, key);
const end = timer.read();
const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s;
const throughput = @floatToInt(u64, BytesToHash / elapsed_s);
try stdout.print("{}: {} MiB/s\n", "poly1305", throughput / (1 * MiB));
}
const std = @import("std");
const time = std.os.time;
const Timer = time.Timer;
const x25519 = @import("x25519.zig");
const MiB = 1024 * 1024;
const BytesToHash = 128 * MiB;
pub fn main() !void {
var stdout_file = try std.io.getStdOut();
var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
const stdout = &stdout_out_stream.stream;
var in = []u8{9} ++ []u8{0} ** 31;
var out = []u8{9} ++ []u8{0} ** 31;
var timer = try Timer.start();
const start = timer.lap();
var i: usize = 0;
_ = x25519.crypto_x25519(out[0..], out, in);
const end = timer.read();
const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s;
try stdout.print("{}: {} exchanges per second\n", "x25519", @floatToInt(usize, 1 / elapsed_s));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment