aboutsummaryrefslogtreecommitdiff
path: root/src/timer.zig
blob: cf56cc6ec83ab4d46fce2789c577f62411665a5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const std = @import("std");

const Timer = @This();

begin: i128 = 0,
elapsed: i128 = 0,

pub fn start(timer: *Timer) void {
    timer.begin = std.time.nanoTimestamp();
}

pub fn stop(timer: *Timer) void {
    timer.elapsed = std.time.nanoTimestamp() - timer.begin;
}

pub fn seconds(timer: *const Timer) f64 {
    return @intToFloat(f64, timer.elapsed) / std.time.ns_per_s;
}