1. Delay()

Alan(?) Coded :
procedure Delay(atom seconds)
atom now

  now = time()
  while (time() - now) < seconds do
  end while
end procedure

However this is more accurate :

procedure Delay(atom seconds)
atom until

  until = time() + seconds
  while time() < until do
  end while
end procedure

Why? Well the first version of delay is doing a function call, a load, a
calculation and then a comparison each time.
But calculations take time.
The second code does the calculation once. It then only does the function call
and comparison each time.

The later is logically quicker. However it is all relative as no *human* would
percieve it.
A machine might.

-----
Sincerely,
Mathew Hounsell
Mat.Hounsell at Mailexcite.Com




Free web-based email, Forever, From anywhere!
http://www.mailexcite.com

new topic     » topic index » view message » categorize

2. Re: Delay()

A very good point, Mathew. I have already amended the pause() routine in my
little box of tricks. jiri

-----Original Message-----
From: Mathew Hounsell <mat.hounsell at MAILEXCITE.COM>
To: EUPHORIA at cwisserver1.mcs.muohio.edu
<EUPHORIA at cwisserver1.mcs.muohio.edu>
Date: Saturday, August 15, 1998 8:31 PM
Subject: Delay()


>Alan(?) Coded :
>procedure Delay(atom seconds)
>atom now
>
>  now = time()
>  while (time() - now) < seconds do
>  end while
>end procedure
>
>However this is more accurate :
>
>procedure Delay(atom seconds)
>atom until
>
>  until = time() + seconds
>  while time() < until do
>  end while
>end procedure
>
>Why? Well the first version of delay is doing a function call, a load, a
calculation and then a comparison each time.
>But calculations take time.
>The second code does the calculation once. It then only does the function
call and comparison each time.
>
>The later is logically quicker. However it is all relative as no *human*
would percieve it.
>A machine might.
>
>-----
>Sincerely,
>Mathew Hounsell
>Mat.Hounsell at Mailexcite.Com
>
>
>
>
>Free web-based email, Forever, From anywhere!
>http://www.mailexcite.com
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Delay()

twas I, and yes, you make a very good optimization
that is also going to be put back in my toolbox as well.
thanks for your sharp eye... and, yes, ticks count :)

Mathew Hounsell wrote:
>
> Alan(?) Coded :
> procedure Delay(atom seconds)
> atom now
>
>   now = time()
>   while (time() - now) < seconds do
>   end while
> end procedure
>
> However this is more accurate :
>
> procedure Delay(atom seconds)
> atom until
>
>   until = time() + seconds
>   while time() < until do
>   end while
> end procedure
>
> Why? Well the first version of delay is doing a function call, a load, a
> calculation and then a comparison each time.
> But calculations take time.
> The second code does the calculation once. It then only does the function call
> and comparison each time.
>
> The later is logically quicker. However it is all relative as no *human* would
> percieve it.
> A machine might.
>
> -----
> Sincerely,
> Mathew Hounsell
> Mat.Hounsell at Mailexcite.Com
>
> Free web-based email, Forever, From anywhere!
> http://www.mailexcite.com

new topic     » goto parent     » topic index » view message » categorize

4. Re: Delay()

Hawke, my machine wants to know now what to do with all those cycles saved
while idling anyway... jiri

-----Original Message-----
From: Hawke <mdeland at NWINFO.NET>
To: EUPHORIA at cwisserver1.mcs.muohio.edu
<EUPHORIA at cwisserver1.mcs.muohio.edu>
Date: Saturday, August 15, 1998 10:28 PM
Subject: Re: Delay()


>twas I, and yes, you make a very good optimization
>that is also going to be put back in my toolbox as well.
>thanks for your sharp eye... and, yes, ticks count :)

new topic     » goto parent     » topic index » view message » categorize

5. Re: Delay()

On Sat, 15 Aug 1998 01:29:46 -0700 Mathew Hounsell
<mat.hounsell at MAILEXCITE.COM> writes:
>Alan(?) Coded :
>procedure Delay(atom seconds)
>atom now
>
>  now = time()
>  while (time() - now) < seconds do
>  end while
>end procedure
>
>However this is more accurate :
>
>procedure Delay(atom seconds)
>atom until
>
>  until = time() + seconds
>  while time() < until do
>  end while
>end procedure
>
>Why? Well the first version of delay is doing a function call, a load,
>a calculation and then a comparison each time.
>But calculations take time.
>The second code does the calculation once. It then only does the
>function call and comparison each time.
>
>The later is logically quicker. However it is all relative as no
>*human* would percieve it.
>A machine might.

First: Optimizing a DELAY routine. Sad. :) (Ok, so I've done it also....
:)

Second: They both have a bug.

The bug? time() seems to roll over to 0 again after 24 hours of running
the program.

until = time() + seconds    --time = .05 seconds less than 24 hours of
seconds
                            -- + 1 second delay makes it .5 seconds past
the
                            -- maximum time() can return.
while time() < until do     -- Never true. until is more than time()
could
                            -- ever be
end while


Depending on how much time is spent in the idle loop, and how long the
program is intended to run, the program may crash sometimes and not
others. It's happened to me... (Yes, I ran a screen saver [based on
Vector] for over 24 hours and it halted itself in the loop.) I have a
solution, but it's more of a GAME PROGRAMMING solution so you may not
care about it. :) (The way it works, it doesn't count seconds, it counts
the number of times the clock updates.)
(Now the screen saver can run for weeks and it won't crash. :)

If you set tick_rate() to 30 and call tick_delay(1) per loop you'll get
30 loops per second. (Or if it's a game, 30 frames per second.) If you
call tick_delay(30) you'll get a 1 second delay.


global procedure tick_delay(atom l)
    -- A l pause. Makes use of the 18.2 ticks... (l for lenght...)
    atom oldtime                                -- Last time()
    integer ticks                               -- Total ticks counted

    oldtime = time()                            -- Get time
    ticks = 0                                   -- No ticks yet
    while l > ticks do                          -- Loop until enough
ticks
        while oldtime = time() do end while     -- Wait for time() update
        ticks = ticks + 1                       -- Tick has elapsed
        oldtime = time()                        -- Update oldtime
    end while                                   -- End of loop
end procedure


_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » goto parent     » topic index » view message » categorize

6. Delay()

Well spotted Robert. No I'm not 'sad' for optimising it. You see it wasn't my
idea. It was either ( in descending order of likely hood ) Dave's, Irv's or
Rob's. I was going to say that in the last message but I thought it unimportant.
I just got guilty because of the un-due praise.

-----
Sincerely,
Mathew Hounsell
Mat.Hounsell at Mailexcite.Com


Free web-based email, Forever, From anywhere!
http://www.mailexcite.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu