Darkbyte Library

Nonstandard Web Browser

It appears that your browser does not comply with the W3C web standards which define how web pages are encoded, transmitted, and rendered. This site would look much better in a standards-compliant web browser, but its content is accessible to any browser or Internet device.

CPU Speed Display :: Show your current CPU speed in MHz.

Download

License : LGPL

Description :
A simple console application to report the current CPU speed in MHz. This sample will ONLY work on Pentium class PC's or higher ... you have been warned. It's been tested under Linux and Windows 2000.

Source Code :


/******************************************************************************
 * CPU Speed
 * ---------
 * Author: Alan Doyle (alan.doyle@darkbyte.com)
 * Copyright: (c) 2005 Darkbyte Software
 * Release Version: 1.0
 * Date Started: 2005/08/03
 *
 * Display the current CPU Speed in MHz ( Pentium class PC's or higher ).
 * Tested under Linux, Windows 2000 and Windows XP.
 *
 ******************************************************************************
 *
 *   cpu.c is free software; you can redistribute it and/or modify
 *   it under the terms of the Lesser General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   cpu.c is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the Lesser General Public License
 *   along with cpu.c; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 ******************************************************************************/
 
#include <stdio.h>
 
#ifdef WIN32
#include <windows.h>
 
#define rdtsc(low, high)  \
	__asm \
	{ \
	__asm _emit 0x0f \
	__asm _emit 0x31 \
	__asm mov high,edx \
	__asm mov low,eax \
	}
 
void usleep( unsigned long delay )
{
	Sleep( delay / 1000 );
}
#else
#define rdtsc(low,high) \
	__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
#endif
 
int main( void )
{
	unsigned long startlow, starthigh;
	unsigned long endlow, endhigh;
	unsigned long delay = 500;
 
	rdtsc(startlow,starthigh);
	usleep( delay * 1000 );
	rdtsc(endlow,endhigh);
 
	printf("CPU Speed : %d MHz\n", ( ( endlow - startlow ) / ( 1000 * delay ) ) );
 
	return 0;
}
Copyright © 2000-2008 Darkbyte Software, All Rights Reserved. 
Please direct your questions or comments to

CCBot/1.0 (+http://www.commoncrawl.org/bot.html) [38.103.63.57 ( )]