[TUTORIAL] C++ How fast is your CPU?

Remis

Well-Known Member
Messages
663
C++ How fast is your CPU?


This tutorial shows you how to create a programm in C++ which gets the basic CPU measurement
All explanations are in the comments of the following code.


Code:
#include <iostream>
using namespace std;
#include <time.h>

int main()
{
cout << "[themavesite.com] CPU benchmark started" << endl;
clock_t start,end; 
start = clock();                                  //clock() gets the wasted CPU time
				 //At the beginning we get the starting time, because its not necessarily guarantee
				 //that no ticks have been counted.
for(int i=0; i<999999999;i++)
{
	                                              //some progressing stuff for the CPU
                                                            // CPU turns evil
}

end = clock();                                	          //we get the starting time again
cout << start << endl;                        		//prints start time in the console
cout << end << ":" << CLOCKS_PER_SEC << endl;//prints the end time and the constant
                                                                                     // CLOCKS_PER_SEC (1.000.000 on all POSIX-Systems)
	cin.get();
}

For all who never made anything in C++, but are interested:

Where to get a C++ IDE:
http://www.microsoft.com/express/vc/

(Forget the gamescreator stuff, it sucks. But feel free to test it on your own)

Create a console project.

Add the code and compile.

How to compile it on a linux system

1.Get g++ with the installer tool of your OS. (apt-get in Debian, Yast in OpenSuse...)
2.Open the terminal and compile your cpu.cpp file with this:

Code:
g++ -o CPU cpu.cpp

Download compiled .exe:
http://www.s244862283.online.de/downloads/cpu.exe
http://www.s244862283.online.de/downloads/24234_cpu.exe

Only for Linux:
http://www.s244862283.online.de/downloads/cpu

Download source:
http://pastebin.com/f30779f98


ty for reading my tutorial :book:

post your results :wow:
 
Re: C++ How fast is your CPU?

i get errors

1>------ Build started: Project: CPU Tester, Configuration: Debug Win32 ------
1>Compiling...
1>CPU Tester.cpp
1>.\CPU Tester.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>.\CPU Tester.cpp(3) : warning C4627: '#include <time.h>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>.\CPU Tester.cpp(25) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://d:\My Documents\Visual Studio 2008\Projects\CPU Tester\CPU Tester\Debug\BuildLog.htm"
1>CPU Tester - 1 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 
Re: C++ How fast is your CPU?

In the Windows compiler you need to include the stdafx header.(like it says in the errors)
Try this:
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <time.h>

int main()
{
cout << "[themavesite.com] CPU benchmark started" << endl;
clock_t start,end; 
start = clock(); //clock() gets the wasted CPU time
				 //At the beginning we get the starting time, because its not necessarily guarantee
				 //that no ticks have been counted.
for(int i=0; i<999999999;i++)
{
	                          //some progressing stuff for the CPU :D
					          // CPU turns evil
}

end = clock();                                //we get the starting time again
cout << start << endl;                        //prints start time in the console
cout << end << ":" << CLOCKS_PER_SEC << endl; //prints the end time and the constant
											  // CLOCKS_PER_SEC (1.000.000 on all POSIX-Systems)

	cin.get();
}
 
Re: C++ How fast is your CPU?

ok i did that but the end result is in some weird file .sln i opened it as a new console
 
Re: C++ How fast is your CPU?

Um, if your already using C++ why not make a tiny app for me so I don't have to download C++ for this?
 
Re: C++ How fast is your CPU?

Try to debug (F5), does it work?
The compiled .exe should be there:
Documents\Visual Studio 2008\Projects
then there is somewhere the compiled .exe. Iam using Vista, idk where it is in XP.

Um, if your already using C++ why not make a tiny app for me so I don't have to download C++ for this?
There is already a compiled execute app in my post. Is that what do you mean? :woot:
 
Re: C++ How fast is your CPU?

mines good now i found it (debug folder for xp users for example My Documents\Visual Studio 2008\Projects\.........\Debug
 
Re: C++ How fast is your CPU?

Uhhhhh, Nice Program but i just deleted my Microsoft C++ compiler thingy :tongue: and it takes a hell lot of time to reinstall xD ill test it later :thumbsup:
 
Re: C++ How fast is your CPU?

The compiled exe doesn't work for me :/
 
Re: C++ How fast is your CPU?

Then try this one:
http://www.s244862283.online.de/downloads/24234_cpu.exe
I used an another compiler for this one. This should work with every Windows OS.
 
Re: C++ How fast is your CPU?

Heres what it said for me:
31
2890:1000


What does that mean :wow:
 
Re: C++ How fast is your CPU?

so lower the better?
 
Re: C++ How fast is your CPU?

I doubt I beat you, this is my prosessor
Intel(R) Pentium(R) 4 CPU 3.00GHz
 
Back
Top Bottom