Thanks to the Windows Process Environment Block, it is possible to obtain handles to the standard input, output, and error streams without possibility of failure.
36 lines
1.0 KiB
Zig
36 lines
1.0 KiB
Zig
const builtin = @import("builtin");
|
|
const std = @import("std");
|
|
|
|
pub fn main() !void {
|
|
const stdout = &std.io.getStdOut().outStream().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"
|
|
);
|
|
}
|