| author | |
| committer | |
| log | de489031d873193ca94de1292828c00a02e3b3ea |
| tree | 2a9e8a8e5e0b78311005d455d81e8bd2f0845b6e |
| parent | 37ecaae6390d238dce21ef4b97e6994dd229c2c3 |
6 files changed, 59 insertions(+), 12 deletions(-)
lib/compiler/reduce.zig+1-1| ... | ... | @@ -68,7 +68,7 @@ pub fn main() !void { |
| 68 | 68 | const arg = args[i]; |
| 69 | 69 | if (mem.startsWith(u8, arg, "-")) { |
| 70 | 70 | if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| 71 | const stdout = std.fs.File.stdout().deprecatedWriter(); | |
| 71 | const stdout = std.fs.File.stdout(); | |
| 72 | 72 | try stdout.writeAll(usage); |
| 73 | 73 | return std.process.cleanExit(); |
| 74 | 74 | } else if (mem.eql(u8, arg, "--")) { |
lib/std/Random/benchmark.zig+13-1| ... | ... | @@ -122,7 +122,9 @@ fn mode(comptime x: comptime_int) comptime_int { |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | pub fn main() !void { |
| 125 | const stdout = std.fs.File.stdout().deprecatedWriter(); | |
| 125 | var stdout_buffer: [0x100]u8 = undefined; | |
| 126 | var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); | |
| 127 | const stdout = &stdout_writer.interface; | |
| 126 | 128 | |
| 127 | 129 | var buffer: [1024]u8 = undefined; |
| 128 | 130 | var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); |
| ... | ... | @@ -139,6 +141,7 @@ pub fn main() !void { |
| 139 | 141 | while (i < args.len) : (i += 1) { |
| 140 | 142 | if (std.mem.eql(u8, args[i], "--mode")) { |
| 141 | 143 | try stdout.print("{}\n", .{builtin.mode}); |
| 144 | try stdout.flush(); | |
| 142 | 145 | return; |
| 143 | 146 | } else if (std.mem.eql(u8, args[i], "--filter")) { |
| 144 | 147 | i += 1; |
| ... | ... | @@ -179,6 +182,8 @@ pub fn main() !void { |
| 179 | 182 | inline for (prngs) |R| { |
| 180 | 183 | if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) { |
| 181 | 184 | try stdout.print("{s} (long outputs)\n", .{R.name}); |
| 185 | try stdout.flush(); | |
| 186 | ||
| 182 | 187 | const result_long = try benchmark(R, count, long_block_size); |
| 183 | 188 | try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)}); |
| 184 | 189 | } |
| ... | ... | @@ -188,6 +193,8 @@ pub fn main() !void { |
| 188 | 193 | inline for (prngs) |R| { |
| 189 | 194 | if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) { |
| 190 | 195 | try stdout.print("{s} (short outputs)\n", .{R.name}); |
| 196 | try stdout.flush(); | |
| 197 | ||
| 191 | 198 | const result_short = try benchmark(R, count, short_block_size); |
| 192 | 199 | try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)}); |
| 193 | 200 | } |
| ... | ... | @@ -199,6 +206,8 @@ pub fn main() !void { |
| 199 | 206 | inline for (csprngs) |R| { |
| 200 | 207 | if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) { |
| 201 | 208 | try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name}); |
| 209 | try stdout.flush(); | |
| 210 | ||
| 202 | 211 | const result_long = try benchmark(R, count, long_block_size); |
| 203 | 212 | try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)}); |
| 204 | 213 | } |
| ... | ... | @@ -208,10 +217,13 @@ pub fn main() !void { |
| 208 | 217 | inline for (csprngs) |R| { |
| 209 | 218 | if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) { |
| 210 | 219 | try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name}); |
| 220 | try stdout.flush(); | |
| 221 | ||
| 211 | 222 | const result_short = try benchmark(R, count, short_block_size); |
| 212 | 223 | try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)}); |
| 213 | 224 | } |
| 214 | 225 | } |
| 215 | 226 | } |
| 216 | 227 | } |
| 228 | try stdout.flush(); | |
| 217 | 229 | } |
lib/std/crypto/benchmark.zig+2-1| ... | ... | @@ -460,7 +460,8 @@ fn mode(comptime x: comptime_int) comptime_int { |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | pub fn main() !void { |
| 463 | var stdout_buffer: [4096]u8 = undefined; | |
| 463 | // Size of buffer is about size of printed message. | |
| 464 | var stdout_buffer: [0x100]u8 = undefined; | |
| 464 | 465 | var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); |
| 465 | 466 | const stdout = &stdout_writer.interface; |
| 466 | 467 |
lib/std/hash/benchmark.zig+31-6| ... | ... | @@ -19,8 +19,11 @@ const Hash = struct { |
| 19 | 19 | has_iterative_api: bool = true, |
| 20 | 20 | has_crypto_api: bool = false, |
| 21 | 21 | has_anytype_api: ?[]const comptime_int = null, |
| 22 | /// `final` value should be read from this field. | |
| 23 | has_struct_api: ?[]const u8 = null, | |
| 22 | 24 | init_u8s: ?[]const u8 = null, |
| 23 | 25 | init_u64: ?u64 = null, |
| 26 | init_default: bool = false, | |
| 24 | 27 | }; |
| 25 | 28 | |
| 26 | 29 | const hashes = [_]Hash{ |
| ... | ... | @@ -54,6 +57,8 @@ const hashes = [_]Hash{ |
| 54 | 57 | Hash{ |
| 55 | 58 | .ty = hash.Adler32, |
| 56 | 59 | .name = "adler32", |
| 60 | .has_struct_api = "adler", | |
| 61 | .init_default = true, | |
| 57 | 62 | }, |
| 58 | 63 | Hash{ |
| 59 | 64 | .ty = hash.crc.Crc32, |
| ... | ... | @@ -112,21 +117,29 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize, allocator: std.mem.Alloc |
| 112 | 117 | |
| 113 | 118 | const block_count = bytes / block_size; |
| 114 | 119 | |
| 115 | var h = blk: { | |
| 120 | var h: H.ty = blk: { | |
| 116 | 121 | if (H.init_u8s) |init| { |
| 117 | break :blk H.ty.init(init[0..H.ty.key_length]); | |
| 122 | break :blk .init(init[0..H.ty.key_length]); | |
| 118 | 123 | } |
| 119 | 124 | if (H.init_u64) |init| { |
| 120 | break :blk H.ty.init(init); | |
| 125 | break :blk .init(init); | |
| 121 | 126 | } |
| 122 | break :blk H.ty.init(); | |
| 127 | if (H.init_default) { | |
| 128 | break :blk .{}; | |
| 129 | } | |
| 130 | break :blk .init(); | |
| 123 | 131 | }; |
| 124 | 132 | |
| 125 | 133 | var timer = try Timer.start(); |
| 126 | 134 | for (0..block_count) |i| { |
| 127 | 135 | h.update(blocks[i * block_size ..][0..block_size]); |
| 128 | 136 | } |
| 129 | const final = if (H.has_crypto_api) @as(u64, @truncate(h.finalInt())) else h.final(); | |
| 137 | const final = if (H.has_struct_api) |field_name| | |
| 138 | @field(h, field_name) | |
| 139 | else if (H.has_crypto_api) | |
| 140 | @as(u64, @truncate(h.finalInt())) | |
| 141 | else | |
| 142 | h.final(); | |
| 130 | 143 | std.mem.doNotOptimizeAway(final); |
| 131 | 144 | |
| 132 | 145 | const elapsed_ns = timer.read(); |
| ... | ... | @@ -340,7 +353,9 @@ fn mode(comptime x: comptime_int) comptime_int { |
| 340 | 353 | } |
| 341 | 354 | |
| 342 | 355 | pub fn main() !void { |
| 343 | const stdout = std.fs.File.stdout().deprecatedWriter(); | |
| 356 | var stdout_buffer: [0x100]u8 = undefined; | |
| 357 | var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); | |
| 358 | const stdout = &stdout_writer.interface; | |
| 344 | 359 | |
| 345 | 360 | var buffer: [1024]u8 = undefined; |
| 346 | 361 | var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); |
| ... | ... | @@ -360,6 +375,7 @@ pub fn main() !void { |
| 360 | 375 | while (i < args.len) : (i += 1) { |
| 361 | 376 | if (std.mem.eql(u8, args[i], "--mode")) { |
| 362 | 377 | try stdout.print("{}\n", .{builtin.mode}); |
| 378 | try stdout.flush(); | |
| 363 | 379 | return; |
| 364 | 380 | } else if (std.mem.eql(u8, args[i], "--seed")) { |
| 365 | 381 | i += 1; |
| ... | ... | @@ -397,6 +413,7 @@ pub fn main() !void { |
| 397 | 413 | key_size = try std.fmt.parseUnsigned(usize, args[i], 10); |
| 398 | 414 | if (key_size.? > block_size) { |
| 399 | 415 | try stdout.print("key_size cannot exceed block size of {}\n", .{block_size}); |
| 416 | try stdout.flush(); | |
| 400 | 417 | std.process.exit(1); |
| 401 | 418 | } |
| 402 | 419 | } else if (std.mem.eql(u8, args[i], "--iterative-only")) { |
| ... | ... | @@ -416,6 +433,7 @@ pub fn main() !void { |
| 416 | 433 | |
| 417 | 434 | if (test_iterative_only and test_small_key_only) { |
| 418 | 435 | try stdout.print("Cannot use iterative-only and small-key-only together!\n", .{}); |
| 436 | try stdout.flush(); | |
| 419 | 437 | usage(); |
| 420 | 438 | std.process.exit(1); |
| 421 | 439 | } |
| ... | ... | @@ -428,6 +446,7 @@ pub fn main() !void { |
| 428 | 446 | if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) hash: { |
| 429 | 447 | if (!test_iterative_only or H.has_iterative_api) { |
| 430 | 448 | try stdout.print("{s}\n", .{H.name}); |
| 449 | try stdout.flush(); | |
| 431 | 450 | |
| 432 | 451 | // Always reseed prior to every call so we are hashing the same buffer contents. |
| 433 | 452 | // This allows easier comparison between different implementations. |
| ... | ... | @@ -435,6 +454,7 @@ pub fn main() !void { |
| 435 | 454 | prng.seed(seed); |
| 436 | 455 | const result = try benchmarkHash(H, count, allocator); |
| 437 | 456 | try stdout.print(" iterative: {:5} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash }); |
| 457 | try stdout.flush(); | |
| 438 | 458 | } |
| 439 | 459 | |
| 440 | 460 | if (!test_iterative_only) { |
| ... | ... | @@ -447,6 +467,7 @@ pub fn main() !void { |
| 447 | 467 | result_small.throughput / size, |
| 448 | 468 | result_small.hash, |
| 449 | 469 | }); |
| 470 | try stdout.flush(); | |
| 450 | 471 | |
| 451 | 472 | if (!test_arrays) break :hash; |
| 452 | 473 | if (H.has_anytype_api) |sizes| { |
| ... | ... | @@ -464,6 +485,7 @@ pub fn main() !void { |
| 464 | 485 | result_ptr.throughput / (1 * MiB), |
| 465 | 486 | result_ptr.hash, |
| 466 | 487 | }); |
| 488 | try stdout.flush(); | |
| 467 | 489 | } |
| 468 | 490 | } |
| 469 | 491 | } |
| ... | ... | @@ -476,6 +498,7 @@ pub fn main() !void { |
| 476 | 498 | result_small.throughput / default_small_key_size, |
| 477 | 499 | result_small.hash, |
| 478 | 500 | }); |
| 501 | try stdout.flush(); | |
| 479 | 502 | |
| 480 | 503 | if (!test_arrays) break :hash; |
| 481 | 504 | if (H.has_anytype_api) |sizes| { |
| ... | ... | @@ -488,6 +511,7 @@ pub fn main() !void { |
| 488 | 511 | result.throughput / (1 * MiB), |
| 489 | 512 | result.hash, |
| 490 | 513 | }); |
| 514 | try stdout.flush(); | |
| 491 | 515 | } |
| 492 | 516 | try stdout.print(" array ptr: \n", .{}); |
| 493 | 517 | inline for (sizes) |exact_size| { |
| ... | ... | @@ -498,6 +522,7 @@ pub fn main() !void { |
| 498 | 522 | result.throughput / (1 * MiB), |
| 499 | 523 | result.hash, |
| 500 | 524 | }); |
| 525 | try stdout.flush(); | |
| 501 | 526 | } |
| 502 | 527 | } |
| 503 | 528 | } |
lib/std/log.zig+2-2| ... | ... | @@ -47,8 +47,8 @@ |
| 47 | 47 | //! // Print the message to stderr, silently ignoring any errors |
| 48 | 48 | //! std.debug.lockStdErr(); |
| 49 | 49 | //! defer std.debug.unlockStdErr(); |
| 50 | //! const stderr = std.fs.File.stderr().deprecatedWriter(); | |
| 51 | //! nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return; | |
| 50 | //! var stderr = std.fs.File.stderr().writer(&.{}); | |
| 51 | //! nosuspend stderr.interface.print(prefix ++ format ++ "\n", args) catch return; | |
| 52 | 52 | //! } |
| 53 | 53 | //! |
| 54 | 54 | //! pub fn main() void { |
lib/std/unicode/throughput_test.zig+10-1| ... | ... | @@ -39,35 +39,44 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount { |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | pub fn main() !void { |
| 42 | const stdout = std.fs.File.stdout().deprecatedWriter(); | |
| 42 | // Size of buffer is about size of printed message. | |
| 43 | var stdout_buffer: [0x100]u8 = undefined; | |
| 44 | var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); | |
| 45 | const stdout = &stdout_writer.interface; | |
| 43 | 46 | |
| 44 | 47 | try stdout.print("short ASCII strings\n", .{}); |
| 48 | try stdout.flush(); | |
| 45 | 49 | { |
| 46 | 50 | const result = try benchmarkCodepointCount("abc"); |
| 47 | 51 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 48 | 52 | } |
| 49 | 53 | |
| 50 | 54 | try stdout.print("short Unicode strings\n", .{}); |
| 55 | try stdout.flush(); | |
| 51 | 56 | { |
| 52 | 57 | const result = try benchmarkCodepointCount("ŌŌŌ"); |
| 53 | 58 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 54 | 59 | } |
| 55 | 60 | |
| 56 | 61 | try stdout.print("pure ASCII strings\n", .{}); |
| 62 | try stdout.flush(); | |
| 57 | 63 | { |
| 58 | 64 | const result = try benchmarkCodepointCount("hello" ** 16); |
| 59 | 65 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 60 | 66 | } |
| 61 | 67 | |
| 62 | 68 | try stdout.print("pure Unicode strings\n", .{}); |
| 69 | try stdout.flush(); | |
| 63 | 70 | { |
| 64 | 71 | const result = try benchmarkCodepointCount("こんにちは" ** 16); |
| 65 | 72 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | 75 | try stdout.print("mixed ASCII/Unicode strings\n", .{}); |
| 76 | try stdout.flush(); | |
| 69 | 77 | { |
| 70 | 78 | const result = try benchmarkCodepointCount("Hyvää huomenta" ** 16); |
| 71 | 79 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 72 | 80 | } |
| 81 | try stdout.flush(); | |
| 73 | 82 | } |