Guest Posted March 30, 2021 On 3/27/2021 at 12:01 AM, emailx45 said: For managed code, the System.Diagnostics.Stopwatch class uses QPC as its precise time basis. hi ALL, I have appoint that "QPC is ON STOPWATCH" since first answer for that topic.... Of course, @Mike Torrettinni want prove yourself that he have some theory better about measure time... as the engineers behind Microsoft or Embarcadero doesnt... as always, the Mike-Topics are always polemics and generate many reply... in Youtube he would be richer. hug Share this post Link to post
Mike Torrettinni 198 Posted March 30, 2021 (edited) 7 minutes ago, emailx45 said: Of course, @Mike Torrettinni want prove yourself that he have some theory better about measure time... as the engineers behind Microsoft or Embarcadero doesnt... Eh, I'm just a Delphi rookie asking questions. I can only dream about being so knowledgeable or experienced to suggest anything to M. or E. But it is interesting that so many factors affect simple 'precise' measurement. Not sure if anybody mentioned, but power usage plan on laptops also affects the QPC a lot! Just tested on my 9 year old laptop and numbers are off the charts away from expected 😉 Edited March 30, 2021 by Mike Torrettinni typo Share this post Link to post
David Heffernan 2347 Posted March 30, 2021 7 minutes ago, emailx45 said: hi ALL, I have appoint that "QPC is ON STOPWATCH" since first answer for that topic No, that's not what you said. You were quoting an MS document that was talking about the .net System.Diagnostics.Stopwatch class. Share this post Link to post
Guest Posted March 30, 2021 1 minute ago, Mike Torrettinni said: But it is interesting that so many factors affect simple 'precise' measurement. Not sure if anybody mentioned, but power usage plan on laptops also affects the QPC a lot! Just tested on my 9 year old laptop and numbers of off the charts away from expected hi @Mike Torrettinni the power consume is descript on links in first anwser that I have post here... if you read the MS links you would know about it. hug Share this post Link to post
David Heffernan 2347 Posted March 30, 2021 3 minutes ago, Mike Torrettinni said: Not sure if anybody mentioned, but power usage plan on laptops also affects the QPC a lot! Well yeah, that's to be expected. And it's not just QPC. If the processor runs in a slower mode, then you code will be slower. And of course when you measure it, that will be reflected, no matter how you measure it. 1 Share this post Link to post
Guest Posted March 30, 2021 (edited) TStopWatch... System.Diagnostics.pas, line 101: ...class function TStopwatch.GetTimeStamp: Int64; ... QueryPerformanceCounter(Result); Winapi.Windows.pas, li ne 38622 function QueryPerformanceCounter; external kernel32 name 'QueryPerformanceCounter'; Winapi.Windows.pas, line 38354 function GetTickCount; external kernel32 name 'GetTickCount'; hug Edited March 30, 2021 by Guest Share this post Link to post
David Heffernan 2347 Posted March 30, 2021 1 minute ago, emailx45 said: TStopWatch... System.Diagnostics.pas, line 101: ...class function TStopwatch.GetTimeStamp: Int64; ... QueryPerformanceCounter(Result); Winapi.Windows.pas, li ne 38622 function QueryPerformanceCounter; external kernel32 name 'QueryPerformanceCounter'; hug I don't think you understand. You talked about a .net class, but we are talking about the Delphi RTL. Share this post Link to post
Guest Posted March 30, 2021 (edited) System.pas, line 6340 procedure Randomize; {$IFDEF MSWINDOWS} var Counter: Int64; begin if not QueryPerformanceCounter(Counter) then Counter := GetTickCount; RandomizeProc( (UInt64(Random(MAXINT)) shl 32) xor UInt64(Counter) ); end; {$ENDIF MSWINDOWS} Winapi.Windows.pas, line 11144 function QueryPerformanceCounter(var lpPerformanceCount: TLargeInteger): BOOL; stdcall; hug Edited March 30, 2021 by Guest Share this post Link to post
David Heffernan 2347 Posted March 30, 2021 2 minutes ago, emailx45 said: System.pas, line 6340 procedure Randomize; {$IFDEF MSWINDOWS} var Counter: Int64; begin if not QueryPerformanceCounter(Counter) then Counter := GetTickCount; RandomizeProc( (UInt64(Random(MAXINT)) shl 32) xor UInt64(Counter) ); end; {$ENDIF MSWINDOWS} hug That's nice. But it's off topic here. 1 Share this post Link to post
Guest Posted March 30, 2021 (edited) https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter Quote BOOL QueryPerformanceCounter( LARGE_INTEGER *lpPerformanceCount ); hug Edited March 30, 2021 by Guest Share this post Link to post
Mike Torrettinni 198 Posted March 30, 2021 (edited) 11 minutes ago, emailx45 said: https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter hug What Delphi version is this? Does it say 200? Like 20.0? Edited March 30, 2021 by Mike Torrettinni Share this post Link to post
Attila Kovacs 629 Posted March 30, 2021 22 minutes ago, David Heffernan said: If the processor runs in a slower mode, then you code will be slower. I thought all the time he is comparing Δt's. What is the point to measure it in seconds? Share this post Link to post
Guest Posted March 30, 2021 (edited) 13 minutes ago, Mike Torrettinni said: What Delphi version is this? Does it say 200? Like 20.0? Edited 3 minutes ago by Mike Torrettinni First, as always I say, I never use "Program Files XX" (sytem folders) to install my softwares like RAD Studio. 200 = 20.0 = RAD Studio RIO == really, decimal dont help me here! look my profile icon on left = Delphi 10.3 Second, I dont think that 10.3 or 10.2 have some change about RTL sources and QPC use by M$ DLL external links, or more, before editions using this DLL... WinAPI hug Edited March 30, 2021 by Guest Share this post Link to post
Mike Torrettinni 198 Posted March 30, 2021 14 hours ago, Stefan Glienke said: Watch some videos by Chandler Carruth like these two: At 17mins he says (paraphrasing): "This whole library has a pile of internal logic to run amazing numbers of iterations until we get something reasonably stable... and here we have example of 22Mio iterations to conclude this operation takes 32 nano seconds... and if I run it again you will some fluctuations..." Wow. Share this post Link to post