Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues to work with zig 0.11 #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions util/timer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pub const Timer = struct {
elapsedTime: u64 = 0,

pub fn start(self: *Timer) void {
self.startTime = @intCast(std.time.microTimestamp());
self.startTime = @intCast(u64, std.time.microTimestamp());
}

pub fn stop(self: *Timer) void {
if (self.startTime != 0) {
var stamp: u64 = @intCast(std.time.microTimestamp());
var stamp: u64 = @intCast(u64, std.time.microTimestamp());
self.elapsedTime = stamp - self.startTime;
}
self.startTime = 0;
Expand All @@ -20,12 +20,12 @@ pub const Timer = struct {
if (self.startTime == 0) {
return self.elapsedTime;
} else {
var stamp: u64 = @intCast(std.time.microTimestamp());
var stamp: u64 = @intCast(u64, std.time.microTimestamp());
return stamp - self.startTime;
}
}

pub fn reset(self: *Timer) void {
self.startTime = @intCast(std.time.microTimestamp());
self.startTime = @intCast(u64, std.time.microTimestamp());
}
};
6 changes: 3 additions & 3 deletions zbench.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const Benchmark = struct {
startTime: u64,

pub fn init(name: []const u8, allocator: *std.mem.Allocator) !Benchmark {
var startTime: u64 = @intCast(std.time.microTimestamp());
var startTime: u64 = @intCast(u64, std.time.microTimestamp());
if (startTime < 0) {
std.debug.warn("Failed to get start time. Defaulting to 0.\n", .{});
startTime = 0;
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn run(comptime func: BenchFunc, bench: *Benchmark, benchResult: *BenchmarkR
const progress = pr * 100;

// Print the progress if it's a new percentage
const currentProgress: u8 = @truncate(progress);
const currentProgress: u8 = @truncate(u8, progress);
if (currentProgress != lastProgress) {
std.debug.print("Progress...({}%)\n", .{currentProgress});
lastProgress = currentProgress;
Expand All @@ -258,7 +258,7 @@ pub fn run(comptime func: BenchFunc, bench: *Benchmark, benchResult: *BenchmarkR
duration = bench.elapsed();

// Adjust N based on the actual duration achieved
bench.N = @intCast((bench.N * MIN_DURATION) / duration);
bench.N = @intCast(usize, (bench.N * MIN_DURATION) / duration);

// Now run the benchmark with the adjusted N value
bench.reset();
Expand Down