Page 1 of 1

Timing you code, how to do that ?`???

Posted: Tue Sep 02, 2008 11:38 am
by kmtdk
Well
as the headline refere: does any one have a way to time you code , since i need one ( both on windows, but also on RHW( no os ))

KMT dk

Re: Timing you code, how to do that ?`???

Posted: Tue Sep 02, 2008 1:40 pm
by Combuster
Use the RDTSC instruction.

It has some pitfalls though, but its pretty much the only OS independent trick you can do.

Re: Timing you code, how to do that ?`???

Posted: Wed Sep 03, 2008 12:35 am
by cyr1x

Code: Select all

#include <ctime>
#include <iostream>
 
using namespace std;
 
class timer
{
public:
    timer() : start(clock()) { }
    ~timer();
private:
    clock_t start;
};
 
inline timer::~timer()
{
    cout << "timer took "<< double(clock()-start)/CLOCKS_PER_SEC
        << " seconds" << endl;

}
Altough it requires C++ and the C++Lib.

Re: Timing you code, how to do that ?`???

Posted: Thu Sep 04, 2008 9:05 am
by kmtdk
well
thx.
when i mean timing, i mean in mili secounds, ( sry not for telling ).

KMT dk

Re: Timing you code, how to do that ?`???

Posted: Fri Sep 05, 2008 6:04 am
by AndrewAPrice
Check here: http://en.wikipedia.org/wiki/RDTSC

Also their external link right at the bottom which reads: "cycle.h - C code to read the high-resolution timer on many CPUs and compilers."

Did you even look in to Combuster's response, which was direct and to the point?