Perry,

"NAP" takes milliseconds as its parameter, but, at least on Windows
platforms, "NAP 1" does not sleep for 1 millisecond, but actually for
about 15 milliseconds.  

It seems that there is a fundamental clock somewhere in the UV Basic
runtime environment on Windows that only 'ticks' about once every
15-and-a-bit milliseconds (I think 15.3 ms from memory).
You can demonstrate this by getting TIME() in a tight loop and seeing
the values and how they change.  You get the same value returned again
and again, then it will jump up by 15 or 16 milliseconds. This has been
the case at least across 9.6, 10.0 and 10.1 - I haven't tried 10.2 yet.

I'd be interested if someone could try this on a Unix / Linux platform
and see if they observe the same phenomenon, or if it's a "Windows
Special Feature" (TM) ;-)
Code to do it is below.

Regards


Mike

-------------------- Begin program code --------------------
* PROGRAM MIKE.SMALLEST.TICK
*
*     What is the shortest time interval that you can NAP?
*     What is the smallest increment value for TIME()? 
*
      THE.START = TIME()
      CRT 'THE.START ':QUOTE(THE.START):' [':OCONV(THE.START,'MTS'):']'
*
*
------------------------------------------------------------------------
-----
*
*     MINIMUM 'NAP'
*
      DIM TIME.ARRAY(10000)
      MAT TIME.ARRAY = ''
      FOR KK = 1 TO 10000
         TIME.ARRAY(KK) = TIME()
         NAP 1
      NEXT KK
      NAP.END = TIME()
      CRT 'NAP.END ':QUOTE(NAP.END)
*
      MIN.DIFF = 999.999
      MAX.DIFF = 0
      DIM DIFF.ARRAY(9999)
      MAT DIFF.ARRAY = ''
      TOT.DIFF = 0
      FOR KK = 2 TO 10000
         THE.DIFF = TIME.ARRAY(KK) - TIME.ARRAY(KK-1)
         IF THE.DIFF GT MAX.DIFF THEN MAX.DIFF = THE.DIFF
         IF THE.DIFF LT MIN.DIFF THEN MIN.DIFF = THE.DIFF
         DIFF.ARRAY(KK-1) = THE.DIFF
         TOT.DIFF += THE.DIFF
      NEXT KK
*
      AVERAGE.DIFF = TOT.DIFF / 9999
      INT.AVERAGE.DIFF = INT((AVERAGE.DIFF * 100000) + 0.5)
*
      CRT 'Average elapsed time of "NAP 1" is ':OCONV(INT.AVERAGE.DIFF,
"MD2"):' milliseconds'
      CRT '     Minimum value of "NAP 1" is ':MIN.DIFF*1000:'
milliseconds'
      CRT '     Maximum value of "NAP 1" is ':MAX.DIFF*1000:'
milliseconds'
*
*
------------------------------------------------------------------------
-----
*
*     SMALLEST INCREMENT OF TIME()
*
      MAT TIME.ARRAY = ''
      FOR KK = 1 TO 1000
         LAST.TIME = TIME()
         THIS.TIME = LAST.TIME
         LOOP
         UNTIL THIS.TIME NE LAST.TIME
            THIS.TIME = TIME()
         REPEAT
         TIME.ARRAY(KK) = THIS.TIME
      NEXT KK
      TIME.END = TIME()
      CRT 'TIME.END ':QUOTE(TIME.END):' [':OCONV(TIME.END,'MTS'):']'
*
      MIN.DIFF = 999.999
      MAX.DIFF = 0
      MAT DIFF.ARRAY = ''
      TOT.DIFF = 0
      FOR KK = 2 TO 1000
         THE.DIFF = TIME.ARRAY(KK) - TIME.ARRAY(KK-1)
         IF THE.DIFF GT MAX.DIFF THEN MAX.DIFF = THE.DIFF
         IF THE.DIFF LT MIN.DIFF THEN MIN.DIFF = THE.DIFF
         DIFF.ARRAY(KK-1) = THE.DIFF
         TOT.DIFF += THE.DIFF
      NEXT KK
*
      AVERAGE.DIFF = TOT.DIFF / 999
      INT.AVERAGE.DIFF = INT((AVERAGE.DIFF * 100000) + 0.5)
*
      CRT 'Average difference of "TIME()" is ':OCONV(INT.AVERAGE.DIFF,
"MD2"):' milliseconds'
      CRT 'Minimum difference of "TIME()" is ':MIN.DIFF*1000:'
milliseconds'
      CRT 'Maximum difference of "TIME()" is ':MAX.DIFF*1000:'
milliseconds'
*
      TOT.DEV.SQUARED = 0
      FOR KK = 1 TO 999
         THIS.DEV = AVERAGE.DIFF - DIFF.ARRAY(KK)
         TOT.DEV.SQUARED += (THIS.DEV * THIS.DEV)
      NEXT KK
*
*
------------------------------------------------------------------------
-----
*
      STOP
*
   END
--------------------- End program code ---------------------

> -----Original Message-----
> From: [EMAIL PROTECTED] On Behalf Of Buss, Troy
(Logitek Systems)
> Sent: Sunday, 14 January 2007 09:30
> To: [email protected]
> Subject: RE: [U2] [UV] Basic Program Scheduling Priority
> 
> Take a look at the NAP statement in UniVerse basic.  I 
> believe it takes tenths or milliseconds as a parameter.
> 
> -Troy
> 
> Perry Taylor wrote:
> > I have several BASIC processes that are quite CPU intensive which I
> > would like to "slow" themselves down a bit so the don't take so much
> > processor time.  Is anyone aware of way for a UniVerse BASIC program
to
> > change it's own processing priority?  Something akin to
> > getpriority()/setpriority() is C?
The information contained in this Internet Email message is intended
for the addressee only and may contain privileged information, but not
necessarily the official views or opinions of the New Zealand Defence Force.
If you are not the intended recipient you must not use, disclose, copy or 
distribute this message or the information in it.

If you have received this message in error, please Email or telephone
the sender immediately.
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to