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

Programming, for all ages and all languages.
Post Reply
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

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

Post 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
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

Use the RDTSC instruction.

It has some pitfalls though, but its pretty much the only OS independent trick you can do.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

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

Post 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.
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

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

Post by kmtdk »

well
thx.
when i mean timing, i mean in mili secounds, ( sry not for telling ).

KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

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

Post 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?
My OS is Perception.
Post Reply