Commit 77bb2dc094
Changed files (3)
lib
std
crypto
hash
test
standalone
guess_number
lib/std/crypto/benchmark.zig
@@ -123,15 +123,6 @@ fn mode(comptime x: comptime_int) comptime_int {
return if (builtin.mode == .Debug) x / 64 else x;
}
-// TODO(#1358): Replace with builtin formatted padding when available.
-fn printPad(stdout: var, s: []const u8) !void {
- var i: usize = 0;
- while (i < 12 - s.len) : (i += 1) {
- try stdout.print(" ", .{});
- }
- try stdout.print("{}", .{s});
-}
-
pub fn main() !void {
const stdout = std.io.getStdOut().outStream();
@@ -175,24 +166,21 @@ pub fn main() !void {
inline for (hashes) |H| {
if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
const throughput = try benchmarkHash(H.ty, mode(32 * MiB));
- try printPad(stdout, H.name);
- try stdout.print(": {} MiB/s\n", .{throughput / (1 * MiB)});
+ try stdout.print("{:>11}: {:5} MiB/s\n", .{H.name, throughput / (1 * MiB)});
}
}
inline for (macs) |M| {
if (filter == null or std.mem.indexOf(u8, M.name, filter.?) != null) {
const throughput = try benchmarkMac(M.ty, mode(128 * MiB));
- try printPad(stdout, M.name);
- try stdout.print(": {} MiB/s\n", .{throughput / (1 * MiB)});
+ try stdout.print("{:>11}: {:5} MiB/s\n", .{M.name, throughput / (1 * MiB)});
}
}
inline for (exchanges) |E| {
if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {
const throughput = try benchmarkKeyExchange(E.ty, mode(1000));
- try printPad(stdout, E.name);
- try stdout.print(": {} exchanges/s\n", .{throughput});
+ try stdout.print("{:>11}: {:5} exchanges/s\n", .{E.name, throughput});
}
}
}
lib/std/hash/benchmark.zig
@@ -172,7 +172,7 @@ fn mode(comptime x: comptime_int) comptime_int {
}
pub fn main() !void {
- const stdout = std.io.getStdOut().outStream();
+ const stdout = std.io.getStdOut().writer();
var buffer: [1024]u8 = undefined;
var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
@@ -248,13 +248,13 @@ pub fn main() !void {
if (H.has_iterative_api) {
prng.seed(seed);
const result = try benchmarkHash(H, count);
- try stdout.print(" iterative: {:4} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash });
+ try stdout.print(" iterative: {:5} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash });
}
if (!test_iterative_only) {
prng.seed(seed);
const result_small = try benchmarkHashSmallKeys(H, key_size, count);
- try stdout.print(" small keys: {:4} MiB/s [{x:0<16}]\n", .{ result_small.throughput / (1 * MiB), result_small.hash });
+ try stdout.print(" small keys: {:5} MiB/s [{x:0<16}]\n", .{ result_small.throughput / (1 * MiB), result_small.hash });
}
}
}
test/standalone/guess_number/main.zig
@@ -4,7 +4,7 @@ const io = std.io;
const fmt = std.fmt;
pub fn main() !void {
- const stdout = io.getStdOut().outStream();
+ const stdout = io.getStdOut().writer();
const stdin = io.getStdIn();
try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});