MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 28 lines 866 B view raw
1const std = @import("std"); 2const builtin = @import("builtin"); 3 4pub var enabled: bool = false; 5 6pub fn log(comptime fmt: []const u8, args: anytype) void { 7 if (!enabled) return; 8 9 var buf: [2048]u8 = undefined; 10 const msg = std.fmt.bufPrint(&buf, "[pkg] " ++ fmt ++ "\n", args) catch return; 11 12 if (comptime builtin.os.tag == .windows) { 13 const handle = std.os.windows.GetStdHandle(std.os.windows.STD_ERROR_HANDLE) catch return; 14 _ = std.os.windows.WriteFile(handle, msg, null) catch {}; 15 } else _ = std.c.write(2, msg.ptr, msg.len); 16} 17 18pub fn timer(comptime label: []const u8, start: u64) u64 { 19 if (!enabled) return start; 20 21 const now = std.time.nanoTimestamp(); 22 const elapsed_ns: u64 = @intCast(now - @as(i128, start)); 23 const elapsed_ms = elapsed_ns / 1_000_000; 24 25 log("{s}: {d}ms", .{ label, elapsed_ms }); 26 27 return @intCast(now); 28}