This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Measuring short times


Dennis, those Solaris functions were not useful for me because I got
no idea how to make it work on Windows.

I found this function in internet: (credits:
http://www.codeproject.com/datetime/NanoSecondTimer.asp?df=100&forumid=29560&exp=0&select=682802)

__inline__ uint64_t rdtsc() {
   uint32_t lo, hi;
   __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
   return (uint64_t)hi << 32 | lo;
}

It gives the 64-bit free counter value of the processor converted to
32-bit and it works wonderful (I could mark one second perfectly
comparing the right values)! The problem is: the frequency of the free
counter varies with the processor frequency, so if I design my program
to my 2.8ghz to wait 500ns, a guy with a 1.4ghz will have this wait
increased for 1ms (1000ns). So I have three choices, and I need some
help because I have no idea of how to go on:

1 ) A way to my program to detect processor's frequency, so it would
calculate the correct counter interval in the beginning and everything
would work fine and every processor would wait the time I want.

2 ) A ready library that would make it for me.

3 ) Another solution that I can't figure out o.o

Thank you very much for reading my message and for the help.
o/



On 11/24/07, Dennis Clarke <dclarke@blastwave.org> wrote:
>
> > Yeah, I'm a programming newbie, so sorry if it's a stupid question.
> >
> > I need to measure a time shorter than 1 milisecond (I need to measure
> > 500 nanoseconds to be exact), but <time.h> seems to give me only the
> > option to have miliseconds. Can someone give me some tip of how to do
> > that?
> >
> > By the way, I'm using a GCC port for Windows that came with Devcpp,
> > maybe it's an useful information.
> >
> > Thank you very much for the help :)
>
> http://www.blastwave.org/man/gethrtime_3C.html
>
> you need Solaris for that to work.
>
>
>
> Dennis
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]