Skip to main content
gamedev.net
🔒 Locked

Profiling Question

Started by sp00n Feb 21, 2005 at 12:33 PM 0 replies 650+ views
Original Post
sp00n
sp00n
I'm currently writing an in-game profiler, in VC++6, using RDTSC. I need some quick-and dirty code for a function to give the processor frequency in MHz so i can work out the timings for my code. Any suggestions? Thanx, sp00n
-= sp00n =-There are 10 kinds of people in this world: those who understand binary and those who don't.
sp00n
sp00n
Well, since you all took so long I knocked one up myself, somewhat influenced by J.M.McGuiness' CCPUTicker Library. here goes:

LARGE_INTEGER	current,finish,onesecond;	double			tot_freq = 0, avg_freq = 0;	__int64			s_tsc,f_tsc;	QueryPerformanceFrequency(&onesecond);			for (int n = 0; n < numloops; n++)	{		QueryPerformanceCounter(&finish);		finish.QuadPart+=onesecond.QuadPart;		{			__asm cpuid									__asm rdtsc									__asm mov dword ptr [s_tsc], eax			__asm mov dword ptr [s_tsc+4], edx		}		do		{			QueryPerformanceCounter(&current);		} while(current.QuadPart<finish.QuadPart);	 		{			__asm cpuid									__asm rdtsc									__asm mov dword ptr [f_tsc], eax			__asm mov dword ptr [f_tsc+4], edx		}				tot_freq += (double)(f_tsc - s_tsc);			}		m_dCPUFreq = tot_freq / numloops;



Hope this is useful to someone :)
-= sp00n =-There are 10 kinds of people in this world: those who understand binary and those who don't.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.