From: Miroslaw Osys
Subject: efficiency problem
Date: 
Message-ID: <bp2vmb$5dv$1@zeus.polsl.gliwice.pl>
Hi, everyone!

I have following issue. In my program there is piece

  (loop for i from 1 to (truncate (/ length 3)) ...
  
which is evaluated (i.e. started) about 1 million times.
Unfortunately result of / is ratio and my clisp 2.30 reports
about almost 17MB of memory used only for storing temporary ratios.
I changed (truncate ...) to (svref array length)
where array is #(0 0 0 1 1 1 2 2 2 ... ) and then memory load is <1kB.
But this is so ugly.

Is there better method to compute floor(length/3) without making 
unnecessary ratios? I tried form
  (truncate (/ length 3.0))
and got 42MB of memory load!

Of course code was compiled (with compile-file).

Thanks for reading
Miroslaw Osys

From: Howard Ding <······@hading.dnsalias.com>
Subject: Re: efficiency problem
Date: 
Message-ID: <m3islmzzay.fsf@frisell.localdomain>
Miroslaw Osys <····@zeus.polsl.gliwice.pl> writes:


>
> Is there better method to compute floor(length/3) without making 
> unnecessary ratios? I tried form
>   (truncate (/ length 3.0))
> and got 42MB of memory load!
>

Why don't you just do either
(truncate length 3)
or
(floor length 3)
depending on which is appropriate for you?

Both take an optional divisor argument.

-- 
Howard Ding
<······@hading.dnsalias.com>
From: Miroslaw Osys
Subject: Re: efficiency problem
Date: 
Message-ID: <bp38kn$71s$1@zeus.polsl.gliwice.pl>
> Why don't you just do either
> (truncate length 3)
> or
> (floor length 3)
> depending on which is appropriate for you?

> Both take an optional divisor argument.

It works!
Thanks

Miroslaw Osys
From: Frank A. Adrian
Subject: Re: efficiency problem
Date: 
Message-ID: <yAatb.1811$196.56533@news.uswest.net>
Miroslaw Osys wrote:

>  (loop for i from 1 to (truncate (/ length 3)) ...

As long as length is not changing outside the loop, why not try

(let ((lim (truncate length 3)))
  (loop for i from 1 to lim ...

This will move the computation out of the loop, as well as returning an
integer to do the comparison with.  If that's still too slow, you can add
declarations for i and lim that might speed up things a bit more.

faa
From: Peter Seibel
Subject: Re: efficiency problem
Date: 
Message-ID: <m3u156ln8h.fsf@javamonkey.com>
"Frank A. Adrian" <·······@ancar.org> writes:

> Miroslaw Osys wrote:
> 
> >  (loop for i from 1 to (truncate (/ length 3)) ...
> 
> As long as length is not changing outside the loop, why not try
> 
> (let ((lim (truncate length 3)))
>   (loop for i from 1 to lim ...
> 
> This will move the computation out of the loop, as well as returning
> an integer to do the comparison with. If that's still too slow, you
> can add declarations for i and lim that might speed up things a bit
> more.

That's not going to help--the elements of a for-from-to clause in LOOP
are only evaluated once anyway. I think Miroslaw's problem is that
this loop is invoked many times and thus the (truncate (/ length 3))
is also invoked a lot.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Miroslaw Osys
Subject: Re: efficiency problem
Date: 
Message-ID: <bp4v5j$p5t$1@zeus.polsl.gliwice.pl>
Hello again!


I tried (truncate length 3) and ratios are not consed any longer.
However there is no need to compute this upper bound in let (I checked this).

Regards, thanks for suggestions

Miroslaw Osys