Taki program żeby troche obciążyć procesor:
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
float zlozona() {
float g, t, w;
for(int i=0; i<1000; i++)
{
t=990.0;
w = (t*2.0*(t/2.0))/(t*(t+1.0)*(t*t*t));
sqrt(w);
for(int i=0; i<1000; i++)
{
t=990.0;
w = (t*2.0*(t/2.0))/(t*(t+1.0)*(t*t*t));
sqrt(w);
for(int i=0; i<1000; i++)
{
t=990.0;
w = (t*2.0*(t/2.0))/(t*(t+1.0)*(t*t*t));
sqrt(w);
}
}
}
return w;
}
int _tmain(int argc, _TCHAR* argv[])
{
time_t start,end;
time (&start);
zlozona();
time (&end);
double dif = difftime (end,start);
printf ("Czas wykonania funkcji wynosi %.2lf sekund.\n", dif );
system("pause");
return 0;
}
Niestety coś jest nie tak bo odpala się konsola i nie wyświetla tego czasu ani komunikatu system("pause"). O co tu chodzi?
Jak usunę jedną pętle for to działa dobrze.