Re: Optimizing for speed

New Message Reply About this list Date view Thread view Subject view Author view

Eric Young (eay@cryptsoft.com)
Thu, 19 Feb 1998 00:39:59 +1000 (EST)


On Tue, 17 Feb 1998, Chuck McManis wrote:
> So I've got some algorithms that I'm trying to squeeze more speed
> out of, and while I'm not quite as fanatical as the DES search
> team I do find myself at a loss for tools. My environment is
> VC++5 on a Win95 platform and what I'd like is something like :
>
> long long t1, t2;
> t1 = snap_time(); /* time in nSecs */
> ... do something ...
> t2 = snap_time();
> printf("This run took %ld nS\n", (long)(t2 - t1));
>
> I've yet to find something in my search through various
> manuals...

Timing of this type of thing can be done at a cycle level via the following
function

//
// gettsc.inl
//
// gives access to the Pentium's (secret) cycle counter
//
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
// in 1996-7 and is entered, by him, into the public domain.

#if defined(__WATCOMC__)
void GetTSC(unsigned long&);
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
#elif defined(__GNUC__)
inline
void GetTSC(unsigned long& tsc)
{
  asm volatile(".byte 15, 49\n\t"
               : "=eax" (tsc)
               :
               : "%edx", "%eax");
}
#elif defined(_MSC_VER)
inline
void GetTSC(unsigned long& tsc)
{
  unsigned long a;
  __asm _emit 0fh
  __asm _emit 31h
  __asm mov a, eax;
  tsc=a;
}
#endif

Now while this works for x86 c++ compilers (and gcc), it is not what you
really want. You probably want to run you code for a few seconds and then
do the divide to work out the speed. For Win32 (96/NT), look at
GetThreadTimes().

eric


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:14:55 ADT