Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2006, 03:16 PM
jdg jdg is offline
Senior Member
 
Join Date: Sep 2003
Posts: 1,051
Default GetTickCount vs. GetTime vs. Now

According to Fitzbean, GetTickCount is not accurate.
[link]http://www.delphipages.com/threads/thread.cfm?ID=163424&G=163306[/link]

He refers to MMSystem.timeGetTime which I can't find in Delphi 4 or Delphi 7 help, though I do find GetTime in Delphi 7 help. It's for use in place of Time on a Linux system. There's no mention of improved accuracy.

I thought I remembered reading on this forum (but couldn't find it) that the difference obtained by subtracting two GetTickCounts was more accurate than that obtained by comparing two times from calling the NOW function.

What is the best way to make micro small time measurements like for measuring execution time? I don't find that help files address the accuracy on any.

jdg.ho

I love this forum. Your generosity is wonderful.
Reply With Quote
  #2  
Old 04-21-2006, 09:25 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,841
Default RE: GetTickCount vs. GetTime vs. Now

This is a Copy/Paste of an article that I found on the web which talks about highly accurate way to measure the execution time:


.................................................. .........
Question/Problem/Abstract:

I am optimizing a function and want to know the difference in execution time before and after optimization in microseconds!!
Answer:


put this in the var section of your function or procedure

Ctr1, Ctr2, Freq,Overhead: int64;
R: extended;


and put this at the beginnig of the function or more generally speaking at the beginning of the code you want to optimize.

[DELPHI] QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(Ctr1);
QueryPerformanceCounter(Ctr2);
Overhead := Ctr2 - Ctr1; // determine API overhead
QueryPerformanceCounter(Ctr1);



put this at the end of the code

QueryPerformanceCounter(Ctr2);
R := ((Ctr2 - Ctr1) - Overhead) / Freq;
showmessage( 'The function took ' + FloatToStr(R) + ' seconds'); [/DELPHI]
important note: remember that the execution time of any function under most operating systems is affected also by services and programs running in the backgroud. So it is adviced that you keep your desktop state constant while optimizing.


This way you will get execution time in microsecond precision.
This is translated to delphi from a vb article at MSDN.

//This is the end of the article.
.................................................. .........


Also see this [link]http://www.swissdelphicenter.ch/en/showcode.php?id=498[/link]

Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 04-23-2006, 06:39 AM
jdg jdg is offline
Senior Member
 
Join Date: Sep 2003
Posts: 1,051
Default RE: GetTickCount vs. GetTime vs. Now

Thanks Jasser,
That's helpful.
I'll let question remain open for a while for additional comment, although there doesn't seem to be much interest.

jdg.ho

I love this forum. Your generosity is wonderful.
Reply With Quote
  #4  
Old 04-28-2006, 10:51 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,841
Default RE: GetTickCount vs. GetTime vs. Now

jdg,

Still wanna keep this open

Regards,
Abdulaziz Jasser
Reply With Quote
  #5  
Old 05-14-2006, 07:30 AM
jdg jdg is offline
Senior Member
 
Join Date: Sep 2003
Posts: 1,051
Default RE: GetTickCount vs. GetTime vs. Now

I was looking for some comments on GetTickCount vs GetTime vs Now. Not really another way to do the same thing. But, what the hey, I'll give you the point for your time. Thanks.

jdg.ho

I love this forum. Your generosity is wonderful.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:54 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.