1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

profile: use specialized time__vpc_now

This commit is contained in:
Delyan Angelov
2020-04-26 20:36:38 +03:00
parent 50a83736ff
commit e523540f3a
5 changed files with 48 additions and 36 deletions

View File

@@ -10,31 +10,29 @@ const (
[typedef]
struct C.mach_timebase_info_data_t {
numer u64
denom u64
numer u32
denom u32
}
fn C.mach_absolute_time() u64
fn C.mach_timebase_info(&C.mach_timebase_info_data_t)
fn C.clock_gettime_nsec_np(int) u64
struct InternalTimeBase {
numer u64
denom u64
numer u32 = 1
denom u32 = 1
}
fn init_time_base() InternalTimeBase {
mut tb := C.mach_timebase_info_data_t{}
tb := C.mach_timebase_info_data_t{}
C.mach_timebase_info(&tb)
return InternalTimeBase{numer:tb.numer, denom:tb.denom}
}
fn sys_mono_now_darwin() u64 {
tm := C.mach_absolute_time()
return mul_div(tm - start_time, time_base.numer, time_base.denom)
}
fn mul_div(val, numer, denom u64) u64 {
q := val / denom
r := val % denom
return q * numer + r * numer / denom
if time_base.denom == 0 {
C.mach_timebase_info(&time_base)
}
return (tm - start_time) * time_base.numer / time_base.denom
}