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 {...@@ -123,15 +123,6 @@ fn mode(comptime x: comptime_int) comptime_int {
123 return if (builtin.mode == .Debug) x / 64 else x;123 return if (builtin.mode == .Debug) x / 64 else x;
124}124}
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
135pub fn main() !void {126pub fn main() !void {
136 const stdout = std.io.getStdOut().outStream();127 const stdout = std.io.getStdOut().outStream();
137128
...@@ -175,24 +166,21 @@ pub fn main() !void {...@@ -175,24 +166,21 @@ pub fn main() !void {
175 inline for (hashes) |H| {166 inline for (hashes) |H| {
176 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {167 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
177 const throughput = try benchmarkHash(H.ty, mode(32 * MiB));168 const throughput = try benchmarkHash(H.ty, mode(32 * MiB));
178 try printPad(stdout, H.name);169 try stdout.print("{:>11}: {:5} MiB/s\n", .{H.name, throughput / (1 * MiB)});
179 try stdout.print(": {} MiB/s\n", .{throughput / (1 * MiB)});
180 }170 }
181 }171 }
182172
183 inline for (macs) |M| {173 inline for (macs) |M| {
184 if (filter == null or std.mem.indexOf(u8, M.name, filter.?) != null) {174 if (filter == null or std.mem.indexOf(u8, M.name, filter.?) != null) {
185 const throughput = try benchmarkMac(M.ty, mode(128 * MiB));175 const throughput = try benchmarkMac(M.ty, mode(128 * MiB));
186 try printPad(stdout, M.name);176 try stdout.print("{:>11}: {:5} MiB/s\n", .{M.name, throughput / (1 * MiB)});
187 try stdout.print(": {} MiB/s\n", .{throughput / (1 * MiB)});
188 }177 }
189 }178 }
190179
191 inline for (exchanges) |E| {180 inline for (exchanges) |E| {
192 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {181 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {
193 const throughput = try benchmarkKeyExchange(E.ty, mode(1000));182 const throughput = try benchmarkKeyExchange(E.ty, mode(1000));
194 try printPad(stdout, E.name);183 try stdout.print("{:>11}: {:5} exchanges/s\n", .{E.name, throughput});
195 try stdout.print(": {} exchanges/s\n", .{throughput});
196 }184 }
197 }185 }
198}186}
lib/std/hash/benchmark.zig+3-3
...@@ -172,7 +172,7 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -172,7 +172,7 @@ fn mode(comptime x: comptime_int) comptime_int {
172}172}
173173
174pub fn main() !void {174pub fn main() !void {
175 const stdout = std.io.getStdOut().outStream();175 const stdout = std.io.getStdOut().writer();
176176
177 var buffer: [1024]u8 = undefined;177 var buffer: [1024]u8 = undefined;
178 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);178 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
...@@ -248,13 +248,13 @@ pub fn main() !void {...@@ -248,13 +248,13 @@ pub fn main() !void {
248 if (H.has_iterative_api) {248 if (H.has_iterative_api) {
249 prng.seed(seed);249 prng.seed(seed);
250 const result = try benchmarkHash(H, count);250 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 });
252 }252 }
253253
254 if (!test_iterative_only) {254 if (!test_iterative_only) {
255 prng.seed(seed);255 prng.seed(seed);
256 const result_small = try benchmarkHashSmallKeys(H, key_size, count);256 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 });
258 }258 }
259 }259 }
260 }260 }
test/standalone/guess_number/main.zig+1-1
...@@ -4,7 +4,7 @@ const io = std.io;...@@ -4,7 +4,7 @@ const io = std.io;
4const fmt = std.fmt;4const fmt = std.fmt;
55
6pub fn main() !void {6pub fn main() !void {
7 const stdout = io.getStdOut().outStream();7 const stdout = io.getStdOut().writer();
8 const stdin = io.getStdIn();8 const stdin = io.getStdIn();
99
10 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});10 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});