I'm at the beginning with C++ and sometimes I don't know how much my compiler will like two different implementation of an alghoritm. Is there a simple tool I can use to see how much time takes my code to execute?
EDIT: Im using gcc compiler
Free
Not Free
If you want to mesure how long the entire program run's, then Code-Blocks/Visual studio should tell you when the program closes. It should be in the log at the bottom.
If you want to mesure how long a specific line, or function takes, I would suggjest researching
clock()
or QueryPerformanceFrequency()
and how to use them.
the clock()
function is slow, but it's easyer to use. an example:
float start_time = clock()/CLOCKS_PER_SEC;
func();
float end_time = clock()/CLOCKS_PER_SEC;
float dtime = start_time - end_time;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With