i want to use the getexecutiontime() for a function in my program, but i want to use it for a function with arguments and the piece of code that i have is not working because my function have arguments
prim_MCST(adj_matrix,nv);

long getExecutionTime(void (*func)()); // define Function

long GetExecutionTime(void (*func)()){
long cTick, nTick;
cTick = GetTickCount();
(*func)();
nTick = GetTickCount();
return nTick - cTick;
}

int main(int argc, char *argv[])
{
cout << "Code executed in: " << GetExecutionTime(doSleep) << "ms \n";…

Recommended Answers

All 10 Replies

yes but is not with the getexecutiontime()!.

yes but is not with the getexecutiontime()!.

Actually it's a better one :)

Can you be more specific? It depends on what your function has to do :)
Can you give an explanation about what your function has to do (I'm talking about prim_MCST(adj_matrix,nv); , what's the link between those two?)
?

actually is a function that use an implementation of prim's algorithm and find the minimun cost spaning tree. so i want to see the performance of my algorthm implementation

So if I don't misunderstand you, you've to write a program which generates prime numbers and you've also to know what time it did take to do the whole operation?

no the prims algorithm is something different. Anyway i dont want anything for the algorithm, i want only to put the getexecutiontime() function in my program to see how long does it take to the algorithm to execute

Actually it's much easier to implement without a function:

  • Step 1 (before the prims algorithm executes): get the time (in seconds) and store it in a variable called time_before (you can also choose something different if you want)
  • Step 2 (after the prims algorithm has executed): get the time again (in seconds) and store it in another variable structure called time_after

Now just subtract both variables :)

hm, and how can i do this ?

hm, and how can i do this ?

Something like this should work (it's only for full seconds, not milliseconds)

time_t tb = time(0); // Begin time
/* 
        Call your algorithm here
*/
time_t ta = time(0); // End time
cout << "Execution time: " << static_cast<long>(ta-tb) << endl;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.