go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
If you are using a Intel processor, there is a single instruction rdtsc which gets you a high resolution timestamp counter with very little overhead. If your compiler allows in-line assembler--or has a _rdtsc() intrinsic--then this can be combined with a small piece of C--as a macro--that fetches the counter and writes it to a buffer along with a line number (from __LINE__) very efficiently. That allows you to tag various points in your C code and gather some stats without overly distorting the timing. Generally, a nice idea, but it does not work unless perl is the only process running, and the OS never schedules another task, and the OS does not run code outside perl (e.g. in kernel mode). rdtsc does not know about processes and threads in the OS. It just counts CPU clock cycles, including those spent in other applications and the kernel. Typical x86-based operating systems (except for DOS) run at least in multi-tasking mode, the better ones can also handle more than one user at a time. On ancient (16 bit) versions of Windows, you could effectively disable task switches by disabling interrupts and not spinning the message loop. But modern operating systems including windows can reschedule a process either when it calls an O/S function or when a timer interrupt occurs. And you can't avoid the latter. The rdtsc function is also available on non-Intel CPUs, and according to http://en.wikipedia.org/wiki/Rdtsc, both Intel and AMD CPUs have some "interesting" differences between their TSC implementations. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) In reply to Re^2: profiling XS routines
by afoken
|
|