www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/04/20/09:07:10

Date: Tue, 20 Apr 1999 09:06:02 -0500
From: Eric Rudd <rudd AT cyberoptics DOT com>
Subject: Re: Slow execution on Windows 9X
To: djgpp-workers AT delorie DOT com
Message-id: <371C89CA.9371A237@cyberoptics.com>
Organization: CyberOptics
MIME-version: 1.0
X-Mailer: Mozilla 4.05 [en] (Win95; U)
References: <Pine DOT SUN DOT 3 DOT 91 DOT 990419180702 DOT 14514H-100000 AT is>
Reply-To: djgpp-workers AT delorie DOT com

Eli Zaretskii wrote:

> We had this discussion before: sometimes, DJGPP programs run slowly in
> Windows DOS box.  I originally thought this was because v2.01 didn't align
> the stack.  However, I now am convinced that v2.02 didn't solve this
> problem.  (I did verify that the stack has its 4 low bits zeroed.)
>
> The funny thing is, some DOS boxes run the same program faster than
> others (about 2-4 times faster, to be exact).  Closing the DOS session
> and reopening it doesn't help.  Rebooting helps, but it only changes
> which DOS boxes run fast and which slow (I need at least Emacs to be
> fast).
>
> What could be the reason for this?  Is something else (code? data?)
> unaligned?  What would be the easiest way to check for these problems?

I don't have the answer to this odd problem, but at the end of this message is
a hacky little program I've found useful in diagnosing such things.  It uses
the Pentium RDTSC instruction, so it may not run on all processors, but
u_clock() isn't reliable under Windows.   Anyway, the program finds the time
difference between successive calls to the timer routine.  If an interrupt
occurs, the time difference will be greater.  The program logs the minimum,
maximum, and mean latencies.

When I run this program under Win95 on my 266-MHz Pentium II, I get an minimum
latency of 33 clocks, and an average of 33.3 -- the Win95 overhead is eating
up about 1% of the time.  On NT, it's more like 10%.  The maximum latency is
usually around 300000 clocks under Win95.

One thing you didn't mention is whether you were running in full-screen mode,
or windowed.  That seems to make a significant difference on my system, with
full-screen mode being invariably faster.

-Eric Rudd
rudd AT cyberoptics DOT com

*******************************

#include <dos.h>
#include <limits.h>
#include <stdio.h>

#define max(x,y) (((x) > (y)) ? (x) : (y))
#define min(x,y) (((x) < (y)) ? (x) : (y))

inline unsigned long long pentimer(int mode) {
   static unsigned long long tref;
   unsigned long long time;

   if (mode == 0) {
      asm ("rdtsc"
         : "=d" (((unsigned long *) &tref)[1]),
           "=a" (((unsigned long *) &tref)[0])
         :
          );
      return 0.;
   } else {
      asm ("rdtsc
            subl  %2, %%eax
            sbbl  %3, %%edx
           "
         : "=d" (((unsigned long *) &time)[1]),
           "=a" (((unsigned long *) &time)[0])
         : "m"  (tref),
           "m"  (((unsigned long *) &tref)[1])
          );
      return time;
   }
}


int main(void) {
   long long n, time, tmax, tmean, tmin;
   int i;

   printf(" Please stand by...\n");
   delay(1500);                        /* Let system settle. */
   tmin = LLONG_MAX;
   tmax = LLONG_MIN;
   n = 0;
   tmean = 0;
   while (!kbhit()) {
      for (i=0; i<1000000; i++) {
         pentimer(0);
         time = pentimer(1);
         tmin = min(tmin, time);
         tmax = max(tmax, time);
         tmean += time;
         n++;
      }
      printf("\r time = [%lld, %lld]; mean = %16.8f",
         tmin, tmax, (double) tmean / (double) n);
      fflush(stdout);
   }
   printf("\n");
   return 0;
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019