Skip to content

cgen: fix profile time on windows #23227

Merged
spytheman merged 2 commits intovlang:masterfrom
kbkpbot:fix-windows-profile-time
Dec 21, 2024
Merged

cgen: fix profile time on windows #23227
spytheman merged 2 commits intovlang:masterfrom
kbkpbot:fix-windows-profile-time

Conversation

@kbkpbot
Copy link
Copy Markdown
Contributor

@kbkpbot kbkpbot commented Dec 20, 2024

Fix issue #19130

QueryPerformanceCounter() only a counter value, it need to divide QueryPerformanceFrequency() to get real time.

As time.vpc_now() return only a counter value:

@[inline]
fn vpc_now() u64 {
	tm := u64(0)
	C.QueryPerformanceCounter(voidptr(&tm))
	return tm
}

https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps

Huly®: V_0.6-21661

@kbkpbot
Copy link
Copy Markdown
Contributor Author

kbkpbot commented Dec 20, 2024

a example :
tt.v

module main
import time

fn main() {
	time.sleep(1000 * time.millisecond)
}

compile it with:

v tt.v -profile

run it and will get result:

D:\v\time>.\tt
             1          0.001ms            600ns at_exit
             1          0.014ms          13600ns _v_malloc
             1          0.014ms          13900ns memdup
             1          0.000ms            200ns gc_set_warn_proc
             1          0.024ms          24200ns is_terminal
             1          0.181ms         181500ns builtin_init
             1          0.006ms           5600ns add_vectored_exception_handler
             1          0.006ms           5600ns add_unhandled_exception_handler
             1       1002.005ms     1002004700ns time__sleep
             1       1002.010ms     1002009500ns main__main

D:\v\time>

Comment thread vlib/v/gen/c/profile.v Outdated
Comment thread vlib/v/gen/c/profile.v Outdated
Comment thread vlib/v/gen/c/profile.v Outdated
Comment thread vlib/v/gen/c/profile.v Outdated
@spytheman spytheman changed the title cgen:fix windows profile time cgen: fix profile time on windows Dec 21, 2024
@spytheman spytheman merged commit 40bb8b1 into vlang:master Dec 21, 2024
@kbkpbot kbkpbot deleted the fix-windows-profile-time branch December 21, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants