diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-07-15 20:46:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-15 20:46:12 -0400 |
| commit | 3f4abe97bdbe666dbb3532c14a97e414aae4caca (patch) | |
| tree | ba08f2f14e79a8c8f7e83cea0344826fefffd9a2 /std/unicode/throughput_test.zig | |
| parent | 33eaaadd01b20d1327b67758664ce1265216e471 (diff) | |
| parent | aff90c22520bbbadd56fbfd1378f161ee8a3cdb2 (diff) | |
| download | zig-3f4abe97bdbe666dbb3532c14a97e414aae4caca.tar.gz zig-3f4abe97bdbe666dbb3532c14a97e414aae4caca.zip | |
Merge pull request #2892 from ziglang/install-with-zig-build
move some of the installation from cmake to zig build
Diffstat (limited to 'std/unicode/throughput_test.zig')
| -rw-r--r-- | std/unicode/throughput_test.zig | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/std/unicode/throughput_test.zig b/std/unicode/throughput_test.zig new file mode 100644 index 0000000000..f8b18af734 --- /dev/null +++ b/std/unicode/throughput_test.zig @@ -0,0 +1,37 @@ +const builtin = @import("builtin"); +const std = @import("std"); + +pub fn main() !void { + var stdout_file = try std.io.getStdOut(); + var stdout_out_stream = stdout_file.outStream(); + const stdout = &stdout_out_stream.stream; + + const args = try std.process.argsAlloc(std.heap.direct_allocator); + + @fence(.SeqCst); + var timer = try std.time.Timer.start(); + @fence(.SeqCst); + + var buffer1: [32767]u16 = undefined; + _ = try std.unicode.utf8ToUtf16Le(&buffer1, args[1]); + + @fence(.SeqCst); + const elapsed_ns_orig = timer.lap(); + @fence(.SeqCst); + + var buffer2: [32767]u16 = undefined; + _ = try std.unicode.utf8ToUtf16Le_better(&buffer2, args[1]); + + @fence(.SeqCst); + const elapsed_ns_better = timer.lap(); + @fence(.SeqCst); + + std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_orig, elapsed_ns_orig / 1000000); + std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_better, elapsed_ns_better / 1000000); + asm volatile ("nop" + : + : [a] "r" (&buffer1), + [b] "r" (&buffer2) + : "memory" + ); +} |
