authorgravatar for datamanrb@gmail.comdata-man <datamanrb@gmail.com> 2020-06-25 21:05:52+05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-25 19:07:25-04:00
log77bb2dc094bfe9fff9208a8af94d0da617bdae13
treeee8d05c4b0e890da62c2a12f4f94b26790377e31
parent41c6cc9001a1a95ea6471c86a1ff4b59890de115

Use writer in benchmarks


3 files changed, 7 insertions(+), 19 deletions(-)

lib/std/crypto/benchmark.zig+3-15
......@@ -123,15 +123,6 @@ fn mode(comptime x: comptime_int) comptime_int {
123123 return if (builtin.mode == .Debug) x / 64 else x;
124124}
125125
126// TODO(#1358): Replace with builtin formatted padding when available.
127fn printPad(stdout: var, s: []const u8) !void {
128 var i: usize = 0;
129 while (i < 12 - s.len) : (i += 1) {
130 try stdout.print(" ", .{});
131 }
132 try stdout.print("{}", .{s});
133}
134
135126pub fn main() !void {
136127 const stdout = std.io.getStdOut().outStream();
137128
......@@ -175,24 +166,21 @@ pub fn main() !void {
175166 inline for (hashes) |H| {
176167 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
177168 const throughput = try benchmarkHash(H.ty, mode(32 * MiB));
178 try printPad(stdout, H.name);
179 try stdout.print(": {} MiB/s\n", .{throughput / (1 * MiB)});
169 try stdout.print("{:>11}: {:5} MiB/s\n", .{H.name, throughput / (1 * MiB)});
180170 }
181171 }
182172
183173 inline for (macs) |M| {
184174 if (filter == null or std.mem.indexOf(u8, M.name, filter.?) != null) {
185175 const throughput = try benchmarkMac(M.ty, mode(128 * MiB));
186 try printPad(stdout, M.name);
187 try stdout.print(": {} MiB/s\n", .{throughput / (1 * MiB)});
176 try stdout.print("{:>11}: {:5} MiB/s\n", .{M.name, throughput / (1 * MiB)});
188177 }
189178 }
190179
191180 inline for (exchanges) |E| {
192181 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {
193182 const throughput = try benchmarkKeyExchange(E.ty, mode(1000));
194 try printPad(stdout, E.name);
195 try stdout.print(": {} exchanges/s\n", .{throughput});
183 try stdout.print("{:>11}: {:5} exchanges/s\n", .{E.name, throughput});
196184 }
197185 }
198186}
lib/std/hash/benchmark.zig+3-3
......@@ -172,7 +172,7 @@ fn mode(comptime x: comptime_int) comptime_int {
172172}
173173
174174pub fn main() !void {
175 const stdout = std.io.getStdOut().outStream();
175 const stdout = std.io.getStdOut().writer();
176176
177177 var buffer: [1024]u8 = undefined;
178178 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
......@@ -248,13 +248,13 @@ pub fn main() !void {
248248 if (H.has_iterative_api) {
249249 prng.seed(seed);
250250 const result = try benchmarkHash(H, count);
251 try stdout.print(" iterative: {:4} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash });
251 try stdout.print(" iterative: {:5} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash });
252252 }
253253
254254 if (!test_iterative_only) {
255255 prng.seed(seed);
256256 const result_small = try benchmarkHashSmallKeys(H, key_size, count);
257 try stdout.print(" small keys: {:4} MiB/s [{x:0<16}]\n", .{ result_small.throughput / (1 * MiB), result_small.hash });
257 try stdout.print(" small keys: {:5} MiB/s [{x:0<16}]\n", .{ result_small.throughput / (1 * MiB), result_small.hash });
258258 }
259259 }
260260 }
test/standalone/guess_number/main.zig+1-1
......@@ -4,7 +4,7 @@ const io = std.io;
44const fmt = std.fmt;
55
66pub fn main() !void {
7 const stdout = io.getStdOut().outStream();
7 const stdout = io.getStdOut().writer();
88 const stdin = io.getStdIn();
99
1010 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});