From: Pascal J. Bourguignon
Subject: Re: Bottleneck rule
Date: 
Message-ID: <87abghbpb8.fsf@hubble.informatimago.com>
Francogrex <······@grex.org> writes:

> I wrote a function which loops through a long list of strings (about a
> 10000) modifies some according to some specified rules and finally it
> groups similar strings together. When this is run (even loaded from a
> compiled .fas file), it takes about 2 hours to complete (it's true at
> some level there is an iteration through an array of 10 million rows
> (10000*10000). I was sreading Paul Graham's book and in it he was
> talking about the bottleneck rule and optimizing speed and says: If a
> major bottleneck occurred in the inner loop of some function, we might
> add
> a declaration like the following:
> (defun bottleneck (...)
>   (do (...)
>     (...)
>     (do (...)
>       (...)
>       (declare (optimize (speed 3) (safety 0)))
>       ...) ) )
>
> But I have no idea how to use that in my code? Anyone has any hint?
> thanks. Below I attach the function just for info.
> ----------------------------------------------------------------------------------------------------------------------------------------
> (defun GroupModifyStrings (intres)
>   (defun scan (file)

Do not do that.  It's equivalent to writing a C function such as:

int group_modify_strings(int res){
   write_to_file("scan.c","int scan(FILE* file){ ...
               ...}");
   system("gcc -o scan.o scan.c");
   void* h=dlopen("scan.o");
   int (*scan)(FILE*);
   scan=dlsym(h,"scan");
   ...
}

This is not scheme.

If you insist having local functions, use FLET or LABELS, not embedded
DEFUN.

   
>   (setf jj 0)

Don't do that.  This force writing into the memory, which uses energy,
and increase global warming.  Use:

(let ((jj 0)) 
   ...)



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This is a signature virus.  Add me to your signature and help me to live.
From: Pascal J. Bourguignon
Subject: Re: Bottleneck rule
Date: 
Message-ID: <7ciqv48slr.fsf@pbourguignon.anevia.com>
Francogrex <······@grex.org> writes:
> Thanks, I took your suggestions and changed. But now I'm stuck with
> another problem, actually it's the first time I'm correcting such a
> large list (>= 10000) and after 40 min of running it breaks with this
> error:
> make-array: dimension 50986740 is not of type '(integer 0 (,array-
> dimension-limit)). I'm sure there must be a declaration to avoid this
> happening but can someone tell me what it is? I use Clisp. Thanks.

You could buy a 64-bit processor. 
There clisp's ARRAY-DIMENSION-LIMIT is 4294967296.

Otherwise, there's no declaration to increase the addressable memory.

You will have to improve the time and space complexities of your algorithms.

-- 
__Pascal Bourguignon__