Advertisement

how to get cpu mhz in c/c++?

Started by January 21, 2001 08:45 AM
6 comments, last by alistair b 23 years, 10 months ago
for a project i''m doing, i need to be able to workout how fast the cpu is (also which sort, but thats harder i think)... can anyone tell me how to ask the cpu/bois/whatever what speed the cpu is? - like sandra says you''ve got a cel2 600 but its running at 900 - how do i do that? thanks alistair
not sure but...
mebbe time a bunch of statements on a test machine. calibrate and see how much it takes on target machine n then get mhz

also windoz registry has a key for cpu mhz
Advertisement
  DWORD GetCpuSpeed(){	int				timeStart	= 0;	int				timeStop	= 0;	unsigned long   StartTicks	= 0;	unsigned long   EndTicks	= 0;	unsigned long   TotalTicks	= 0;	unsigned long   cpuSpeed	= 0;	timeStart = timeGetTime();				// Get tick edge	for( ; ; )	{		timeStop = timeGetTime();		if ( (timeStop-timeStart) > 1 )		// rollover past 1		{			__asm{				xor    eax, eax					xor    ebx, ebx					xor    ecx, ecx					xor    edx, edx					_emit  0x0f				// CPUID					_emit  0xa2					_emit  0x0f				// RTDSC					_emit  0x31					mov    [StartTicks], eax	// Tick counter starts here			}			break;		}	}	timeStart = timeStop;		for( ; ; )	{		timeStop = timeGetTime();		if ( (timeStop-timeStart) > 1000 )	// one second		{			__asm{				xor    eax, eax					xor    ebx, ebx					xor    ecx, ecx					xor    edx, edx					_emit  0x0f					_emit  0xa2					_emit  0x0f					_emit  0x31					mov    [EndTicks], eax			}			break;			}	}	TotalTicks = EndTicks-StartTicks;		// total 	cpuSpeed = TotalTicks/1000000;			// speed	return((DWORD)cpuSpeed);}  


HHSDrum@yahoo.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
well, i''ve no idea how it works (the asm bit), but it does work! thank you very much julio!

alistair
I got an error when I added that code and compiled.

quote:
error LNK2001: unresolved external symbol __imp__timeGetTime@0
Debug/OpenGL.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.



Do you know what this could be? Are there any librarys that I have to link in the settings option? Or is there any specific place the code needs to go?


Hope you can help.

Thanx.

~Cobra~
"Build a man a fire, and he will be warm for a day. Set a man on fire, and he will have warmth for the rest of his life"
Hi,

Juste include time.h
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Advertisement
also be sure you have winmm.lib linked.

HHSDrum@yahoo.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
If you go to amd.com, and download the AMD-SDK, they have a function in one of their lib''s source code files that can tell you what type of CPU they user has. I would post it here, but it spans a header and a .c file, and is pretty big .


http://www.gdarchive.net/druidgames/

This topic is closed to new replies.

Advertisement