Zrobiłem ulepszoną wersję, która testuje oprócz procesora testuje pamięć ram i pamięć masową. Od razu mówię, że mam wątpliwości czy wszystko zrobiłem tak jak należy. Na innym forum słyszałem uwagi, że test CPU wykonuje tylko dodawanie i odejmowanie i, że kod nie jest zoptymalizowany.
#include<iostream>
#include<fstream>
#include<time.h>
using namespace std;
double CPU()
{
clock_t x,y;
unsigned long long a = 0, b = 1;
x=clock();
for (int j=0;j<=9999999;j++)
{
for(int i=0;i<90;i++)
{
b += a;
a = b-a;
}
}
y=clock();
return (double)(y-x)/CLOCKS_PER_SEC;
}
double HDD()
{
clock_t x,y; string xx;
x=clock();
fstream file;
file.open("AMBbenchmark_temp.file.txt");
for (int i=0; i<=10000000; i++)
{
file<<"xxxxxxxxxxxxxxxxxxxxxxx";
getline(file, xx);
}
file.close();
y=clock();
return (double)(y-x)/CLOCKS_PER_SEC;
}
double RAM()
{
clock_t x,y;
int *t;
x=clock();
for (int i=0; i<10000; i++)
{
t=new int [99999];
for (int i=0; i<99999; i++)
{
t[i]=i;
t[i]++;
}
delete [] t;
}
y=clock();
return (double)(y-x)/CLOCKS_PER_SEC;
}
int main()
{
cout<<"AMBbenchmark v1.0 beta."<<endl<<endl;
cout<<"Time processor (one core) is: "<<CPU()<<" seconds."<<endl;
cout<<"Time storage is: "<<HDD()<<" seconds."<<endl;
cout<<"Time Random-access memory is: "<<RAM()<<" seconds."<<endl<<endl;
cout<<"Test was done."<<endl<<"Press any key to close program."<<endl;
cin.get();
return 0;
}
http://przeklej.org/file/ZM6e4b/AMBbenchmark.exe