Sorry about the way the HTML interprets the include directives as code tags and terminates them at the end of the code by the way... can't be helped
#include#include // Link the library we need for the timeGetTime() function #pragma comment (lib, "WINMM.LIB") __int64 getCPUSpeed(unsigned int time) { __int64 timeStart, timeStop; __int64 startTick, endTick; __int64 overhead; overhead = __rdtsc() - __rdtsc(); timeStart = timeGetTime(); while(timeGetTime() == timeStart) { timeStart = timeGetTime(); } for(;;) { timeStop = timeGetTime(); if ((timeStop - timeStart) > 1) { startTick = __rdtsc(); break; } } timeStart = timeStop; for(;;) { timeStop = timeGetTime(); if ((timeStop - timeStart) > time) { endTick = __rdtsc(); break; } } return (__int64)((endTick - startTick) + (overhead)); } int main() { char *cpuSpeed = (char*)malloc(24); sprintf(cpuSpeed, "%d", getCPUSpeed(1000) / 1000000); // Get CPU speed printf("CPU Speed: %c.%c%c%cGhz", cpuSpeed[0], cpuSpeed[1], cpuSpeed[2], cpuSpeed[3]); getchar(); return 0; }
love the post... I want to see moar!
ReplyDeleteI never thought of it that way... interesting
ReplyDelete