[Home] [Puzzles & Projects] [Delphi Techniques] [Math Topics] [Library] [Utilities]
Here's a clever little program that will report CPU speed in Mhz (megahertz - millions of instruction cycles per second). I found it in the Delphi section of experts-exchange.com (search for rdtsc), where it was proposed to resolve a problem of code running slowly on a client's machine. The problem identified in this case was Intel's "SpeedStep" feature for recent mobile processor models which, on some operating systems (e.g. XP), slows the processor to conserve power when operating on batteries. CPUSpeed showed that the processor was only running at 10% of its rated speed! Disabling the feature, resolved the problem.
The program uses the ReadTimeStampCounter (rdtsc) machine instruction to get cycle counter values before and after a 1/2 second delay and subtracting to get the number of instruction cycles during that half-second. An Intel paper available at http://cedar.intel.com/software/idap/media/pdf/rdtscpm1.pdf describes the considerations for using rdtsc. The calculation is almost self defining: cycles per second = cycles / seconds, or, as reported, millions of cycles per second = cycles / microseconds. The programs sets priorities to high values before performing the calculation and restores them after to increase the accuracy of the timing. I've tried it on four computers here and results match CPU specs.
Cool example of using inline assembler instructions and running a windows program with no form (even if you probably won't really need it very often).
Copyright © 2000-2013, Gary Darby
All rights reserved.