DelphiFAQ Home Search:

Reading the CPU clock cycles to measure performance

 

comments4 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

With the Pentium, Intel finally introduced a benchmarking function for their CPUs.

RDTSC - Read Time Stamp Counter

RDTSC returns the number of clock cycles since the CPU was powered up or reset. It can be used for benchmarking without repeating your code thousands of times.

Below is a quick Delphi function that will read the CPU's clock cycle count and return it as a 64bit integer. As said above, this works on a Pentium and higher, meaning 486 CPUs do not have this instruction.

// Returns 64-bit count of CPU clock cycles.
function GetCpuClockCycleCount: Int64;
asm
  dw $310F  // opcode for RDTSC
end;
You don't like the formatting? Check out SourceCoder then!

Comments:

2005-11-16, 20:26:59
kn-hh@web.de from Germany  
yes - works much quicker than QueryPerformanceCounter.
if I only knew, how to find out the frequency of the cpu (ticks/second).
of cource i know the frequency of my cpu, however if the program is running on another pc ....
Any ideas ?
thanx/regards, klaus
2007-03-12, 19:35:12
raygurlz@gmail.com from Australia  
rating
can you please find other measures of a computer’s speed besides the clock cycle?

Keywords: junk

2007-03-18, 19:54:07
anonymous from Australia  
yeah you can connect to a fucking note from the internet malo mata'usi

Keywords:

2007-04-30, 23:58:13
piza-cake from United States  
rating
If you want to determine CPU speed find - > function GetCPUSpeed
in - > JclSysInfo.pas
of Project JEDI Code Library (JCL)

Keywords:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.