GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Sep-2005, 07:48
chorijan chorijan is offline
New Member
 
Join Date: Sep 2005
Location: Croatia
Posts: 1
chorijan is on a distinguished road

[c++]adding cpuid and graph output to my benchmark program


hi people...this is my first post on this forum so i hope you won't get angry if i jump straight to my problem...
you see i'm not that good in c++, but am getting a hang of it.so to upgrade my skills i write little programs for fun. this one is a small benchmark program that uses several mathematical algorithms to measure the speed of the processor by the time it takes them to run the algorithms.
the core of the program is complete and works. but i want to implement a function that will get the os version, cpuid, date and time and display it in the program and a graph that will be used to compare the different results.
all the results are stored in seperate *.txt files and the sum of all results also in a seperate file.
so the question is if you can help me implement this features...and i hope i explained the way the program works and what i want to modify.
thanks for the help in advance.
the code is
CPP / C++ / C Code:
void PascalovTrokut();
void PrimBrojevi();
void Pi();
void CBenchmarkDlg::OnTestiraj() 
{
	
	UpdateData(TRUE);

	if(m_cNaziv == "") {
		MessageBox("Niste unesli tip procesora !!!", "Greska", 48);
		return;
	}

	if((m_bTest1 || m_bTest2 || m_bTest3) != TRUE) {
		MessageBox("Niste izabrali nijedan test !!!", "Greska", 48);
		return;
	}

	m_iRezVri1 = 0;
	m_iRezVri2 = 0;
	m_iRezVri3 = 0;
	m_iRezUkVri = 0;

	m_iVrijeme1 = 0;
	m_iVrijeme2 = 0;
	m_iVrijeme3 = 0;
	m_iUkupnoVri = 0;

	UpdateData(FALSE);


	time_t prvo;
	time_t drugo;

	GetDlgItem(IDC_TESTIRAJ)->EnableWindow(FALSE);
	GetDlgItem(IDC_IZLAZ)->EnableWindow(FALSE);

	
	if(m_bTest1 == TRUE) {
		time(&prvo);
		PascalovTrokut();
		time(&drugo);

		m_iRezVri1 = drugo - prvo;
		m_iVrijeme1 = m_iRezVri1;
		UpdateData(FALSE);
	}


	if(m_bTest2 == TRUE) {
		time(&prvo);
		PrimBrojevi();
		time(&drugo);

		m_iRezVri2 = drugo - prvo;
		m_iVrijeme2 = m_iRezVri2;
		UpdateData(FALSE);
	}


	if(m_bTest3 == TRUE) {
		time(&prvo);
		Pi();
		time(&drugo);

		m_iRezVri3 = drugo - prvo;
		m_iVrijeme3 = m_iRezVri3;
		UpdateData(FALSE);
	}


	m_iRezUkVri = m_iRezVri1 + m_iRezVri2 + m_iRezVri3;
	m_iUkupnoVri = m_iRezUkVri;

	GetDlgItem(IDC_TESTIRAJ)->EnableWindow(TRUE);
	GetDlgItem(IDC_IZLAZ)->EnableWindow(TRUE);

	UpdateData(FALSE);

	if(m_iRezUkVri != 0) {

		char vrijeme[3];
		fstream dat;
		dat.open("Rezultati.txt", ios::app | ios::out);

		dat << m_cNaziv << "\n------------------\n";

		if(m_bTest1 == TRUE) {			
			dat << "Test1:  ";
			_itoa(m_iRezVri1, vrijeme, 10);
			dat << vrijeme << " sekundi\n";
		}

		if(m_bTest2 == TRUE) {
			dat << "Test2:  ";
			_itoa(m_iRezVri2, vrijeme, 10);
			dat << vrijeme << " sekundi\n";
		}

		if(m_bTest3 == TRUE) {
			dat << "Test3:  ";
			_itoa(m_iRezVri3, vrijeme, 10);
			dat << vrijeme << " sekundi\n";
		}

		dat << "Ukupno: ";
		_itoa(m_iRezUkVri, vrijeme, 10);
		dat << vrijeme << " sekundi\n******************\n\n";

		dat.close();

	}

}

void PascalovTrokut() {

	unsigned long br[50000];
	int brojac = 1;
	int brojac2;

	for(brojac; brojac <= 50000; brojac++) {

		int opcija = 0;

		for(brojac2 = 0; brojac2 < brojac; brojac2++) {

			switch(opcija) {

			case 0: br[brojac2] = 1; break;

			case 1:	br[brojac2] = br[brojac2 - 1] + br[brojac2]; break;

			case 2: br[brojac2] = 1; break;

			}

			if(brojac2 == brojac - 2) opcija = 2;
			else opcija = 1;

		}

	}

}

void PrimBrojevi() {

	fstream dat;
	dat.open("Primbrojevi.txt", ios::out | ios::trunc);
	dat << "Prosti brojevi do 100000:\n\n";

	int broj;
	bool primbr;
	char primbroj[6];

	for(broj = 3; broj <= 100000; broj++) {
		primbr = TRUE;

		for(int x = 2; x < broj; x++) {

			if(broj % x == 0) {
				primbr = FALSE;
				break;
			}

		}

		if(primbr == TRUE) {
			_itoa(broj, primbroj, 10);
			dat << primbroj << "\n";
		}

	}

	dat.close();

}

void Pi() {

	fstream dat;
	dat.open("Pi.txt", ios::out | ios::trunc);

	double pi = 0;

	for(int x = 1; x < 2000000000; x += 2) {

		if(x % 4 == 1) pi = pi + double(double(1) / x);
		else pi = pi - double(double(1) / x);

	}

	pi = pi * double(4);

	dat << "Pi = " << pi;

	dat.close();
		
}


void CBenchmarkDlg::OnIzlaz() 
{

	OnOK();
	
}

void CBenchmarkDlg::OnAbout() 
{

	CAboutDlg dlgAbout;
	dlgAbout.DoModal();

}
  #2  
Old 07-Sep-2005, 11:44
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by chorijan
hi people...this is my first post on this forum so i hope you won't get angry if i jump straight to my problem...
Why would we get angry? Our reason to be here is to anwer questions like this

Quote:
Originally Posted by chorijan
the core of the program is complete and works. but i want to implement a function that will get the os version, cpuid, date and time and display it in the program and a graph that will be used to compare the different results.
all the results are stored in seperate *.txt files and the sum of all results also in a seperate file.
For date/time, use one of the functions defined in time.h
For OS version and CPU ID, check the MSDN site (assuming you're using Windows). This link should get you started.
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:10.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.