0

Please can somebody help me ..........
I have no idea on how to implemenet a program to benchmark functions such as insertion , deletion and iteration and deuqe.
I know that I have to use the clock_t function but I can not figure out, if I need to call the clock_t function inside the functions to be tested.

Thank you

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by kc0arf
0

The compiler I am using Visual Studio 2005.
Actually I have some problems with the clock funcion, Allways return 0, I am wondering if there is another way to measure the time.

check this out :

class xyx
{
public:
vector<int> intlist;
clock_t start_time,elapsed;
double elapsed_time;
int i,intN;
vect():start_time(0),elapsed(0),elapsed_time(0),i(0),intN(0)
{
}


void insert_Begin()
{
intN = rand();
start_time = clock();
cout<<clock()<<endl;



intlist.insert(intlist.begin(),rand());
cout<<intlist.front()<<endl;
cout<<clock()<<endl;
elapsed = clock()- start_time;
elapsed_time = elapsed / ((double) CLOCKS_PER_SEC);
cout<<"\n\n";



printf("Time elapsed after a New element was inserted at the biginning: %f\n",elapsed_time);
}


void insert_End()
{
intN = rand();
start_time = clock();



intlist.insert(intlist.end(),rand());
cout<<intlist.back()<<endl;
elapsed = clock()- start_time;
elapsed_time = elapsed / ((double) CLOCKS_PER_SEC);
cout<<"\n\n";


printf("Time elapsed after a New element was inserted at the End: %f\n",elapsed_time);


}
}

Edited by happygeek: fixed formatting

0

Hello,

Actually, look into a "profiler" on your system. Profilers are designed to measure code execution times, and help identify where you need to optimize your code. The profiler design also takes account how much CPU the profiler code consumes,

Check out profilers.

Christian

This article 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.