Hi, I am having a trouble with calculating the run time the purpose of the program is to create a const where the value is determined by reading the time when the program starts. i used ctime as the standard header. in another function it have 2 arrays that it loops 10,000 times multiplying each corresponding elements the array in a single loop. Which then i display the results and the elapse time. This is what I have so far. I am having trouble on getting the run time.
Your setTime/getTime prototypes are nonsense and they don't even match.
Focus a bit more on what you're doing.
Please also note that an optimizing compiler will optimize the entire loop() function away, since it doesn't actually do anything with observable effects. So your elapsed time will always be zero or close to that.
Yeah, see my edit to the previous post.
You can e.g. sum up "result", return it and then print it in main().
That should prevent the removal of the entire function.
Even so, 10000 iterations should take <1 ms, so your result might still be 0.
void ArrayTime::loop()
{
double number1 = 100;
double number2 = 10099;
double array1[10000];
double array2[10000];
for(int i = 0; i <10000; i++)
{
array1[i]= number1;
array2[i] = number2;
constdouble result = array1[i]* array2[i];
number1++;
number2--;
}
int i(1000000000);
while(i--); // ----------> Just to make it take some time
}