News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Dynamic vs static linking

Started by jj2007, April 08, 2017, 06:56:56 PM

Previous topic - Next topic

InfiniteLoop

Ah yes, I made a mistake.

Would you trust an .exe from a random over the internet?

NT is the lowest level, the "native windows API". I assumed its faster and didn't even need to be tested.

Normal call 36 cycles.
Dynamic call 35 cycles.
NT syscall 252 cycles.

zedd151

#31
Quote from: InfiniteLoop on April 07, 2025, 03:51:34 PMWould you trust an .exe from a random over the internet?
From here, from a known member, absolutely. Also, the file can be inspected, if from an unknown source like a brand new member, or an external (meaning not from an attachment on the forum) link.
QuoteNT is the lowest level, the "native windows API".
Ok. I had never bothered with syscalls.

QuoteI assumed its faster and didn't even need to be tested.

Normal call 105 cycles.
Dynamic call 118 cycles.
NT syscall 720 cycles.
Well, now you know.  And so do we.  :biggrin:
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

TimoVJL

Pelles C project using that code
normal: 3925
dynamic: 2676
syscall: 3647

normal: 2833
dynamic: 3341
syscall: 2899
May the source be with you

zedd151

Quote from: TimoVJL on April 07, 2025, 04:00:16 PMPelles C project using that code
normal: 3925
dynamic: 2676
syscall: 3647

normal: 2833
dynamic: 3341
syscall: 2899

first run
normal: 82
dynamic: 46
syscall: 1976

another run
normal: 47
dynamic: 46
syscall: 2085
Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz   3.60 GHz - btw
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

TimoVJL

This Pelles c project test normal call NtQueryPerformanceCounter() too.
No differences ?
May the source be with you

zedd151

C:\Users\Administrator\Downloads\TestDynImpLib_WS2>TestDynImpLib.exe
231 ticks dynamic
231 ticks implib
9842 ticks native

237 ticks dynamic
365 ticks implib
5713 ticks native

231 ticks dynamic
231 ticks implib
5564 ticks native

229 ticks dynamic
230 ticks implib
6366 ticks native

392 ticks dynamic
251 ticks implib
6775 ticks native
C:\Users\Administrator\Downloads\TestDynImpLib_WS2>TestDynImpLib64.exe
125 ticks dynamic
126 ticks implib
4854 ticks native

126 ticks dynamic
139 ticks implib
5131 ticks native

125 ticks dynamic
130 ticks implib
5190 ticks native

126 ticks dynamic
126 ticks implib
5156 ticks native

126 ticks dynamic
126 ticks implib
4873 ticks native
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

TimoVJL

So NtQueryPerformanceCounter() slow in Windows 10 / 11
My test was in Windows 7
May the source be with you

zedd151

Quote from: TimoVJL on April 07, 2025, 10:46:42 PMSo NtQueryPerformanceCounter() slow in Windows 10 / 11
It would seem so.
Windows 10 here.
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

jj2007

Please note that the topic is dynamic vs static linking the same function. Timing two entirely different functions, i.e. ntdll NtQueryPerformanceCounter vs kernel32 QueryPerformanceCounter makes absolutely no sense in this context.

TimoVJL

Quote from: jj2007 on April 08, 2025, 12:32:18 AMPlease note that the topic is dynamic vs static linking the same function. Timing two entirely different functions, i.e. ntdll NtQueryPerformanceCounter vs kernel32 QueryPerformanceCounter makes absolutely no sense in this context.
That function is kernel function, that do QueryPerformanceCounter() and QueryPerformanceFrequency() one go in same function.
Calling it from user level might slow it down.
May the source be with you

jj2007

Quote from: TimoVJL on April 08, 2025, 12:37:02 AMCalling it from user level might slow it down.

In fact, both call eventually QueryPerformanceCounter but the ntdll version passes by a Wow64Transition call:

for (int n=0; n<5; n++) {
pQueryPerformanceCounter((LARGE_INTEGER*)&ll1);
_asm int 3; // jmp near [<&api-ms-win-core-profile-l1-1-0.QueryPerformanceCounter>]
for (i=0; i< 1000; i++)
pQueryPerformanceCounter((LARGE_INTEGER*)&ll2);
printf("%d ticks dynamic\n", ll2-ll1);

QueryPerformanceCounter((LARGE_INTEGER*)&ll1);
for (i=0; i< 1000; i++)
QueryPerformanceCounter((LARGE_INTEGER*)&ll2);
printf("%d ticks implib\n", ll2-ll1);

pNTQueryPerformanceCounter((LARGE_INTEGER*)&ll1, (LARGE_INTEGER*)&ll3);
_asm int 3;
// jmp near [Wow64Transition], followed by jmp far 0033:77787009
// jmp near [<&api-ms-win-core-profile-l1-1-0.QueryPerformanceCounter>]
for (i=0; i< 1000; i++)
pNTQueryPerformanceCounter((LARGE_INTEGER*)&ll2, (LARGE_INTEGER*)&ll3);
printf("%d ticks native\n", ll2-ll1);
printf("\n");
}

TimoVJL

Thanks for testing that mystery.
pNTQueryPerformanceCounter((LARGE_INTEGER*)&ll1, NULL);didn't change speed at all in Windows 7
May the source be with you