Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to time a function in milliseconds without boost::timer

I am using boost 1.46 which does not include boost::timer, What other way can I time my functions.

I am currently doing this:

time_t now = time(0); <some stuff> time_t after = time(0);  cout << after - now << endl;  

but it just gives the answer in seconds, so if the function takes < 1s it displays 0.

Thanks

like image 909
Aly Avatar asked Feb 26 '13 15:02

Aly


Video Answer


1 Answers

In linux or Windows:

#include <ctime> #include <iostream>  int main(int, const char**) {      std::clock_t    start;       start = std::clock();      // your test      std::cout << "Time: " << (std::clock() - start) / (double)(CLOCKS_PER_SEC / 1000) << " ms" << std::endl;      return 0; } 

Good Luck ;)

like image 69
Quentin Perez Avatar answered Oct 04 '22 06:10

Quentin Perez