[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).
October 24, 2016: A kind viewer let me know today that the executable version of CPUSpeed is being flagged as a virus or malware by some security checking software, including Windows Defender on my W10 system. It is a false positive but not worth trying to get the diagnosis changed.
I'm removing the executable download, but leaving the source download. Delphi users can download the source and run it locally with no errors. Zipping the recompiled version locally and running it from there produces a message from Windows "SmartScreen" warning that an unrecognized program is trying to run but it runs fine anyway. Increased security rarely makes everyday operations easier, but is the price we pay to avoid the catastrophic.
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |