-1

i have to calculate the time of call in a prog.
but i dont know how can i calculate the clock time on execution.
will anybody plzzzzzzzz hlp me?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by bsse007
0

I am not sure what you are asking exactly, but I'll take a stab at it, say you
want to measure the time it takes for a specific part of your program to execute.

To get better results, you might want to use QueryPerformanceCounter, rather than clock. But I'll show you an example using the clock function :

#include <iostream>
#include <ctime> //for clock

using namespace std;

int main(){ 

	srand(time(0));

	time_t startTime = time_t();
	time_t endTime = time_t();
	
	const int SZ = 100*100*10;

	long Array[SZ];
	
	startTime = clock(); //start counting time
	for(long i = 0; i  < SZ; ++i){		
			Array[i] = (rand() << i % (i+1))*1.0/RAND_MAX * (rand() >> 1);
	}
	endTime = clock();

	cout << "Time took for the loop to execute was : ";
	cout << endTime - startTime <<" milliseconds = ";
	cout << (endTime-startTime)*1.0/CLOCKS_PER_SEC << " seconds\n";

	return 0;
}
0

thanks.
it is something similar that i asked.
bt i will tell u again if it will not desirably work

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.