eval-stream?

Q&A's, tips, howto's
Post Reply
HPW
Posts: 1377
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

eval-stream?

Post by HPW »

There was this topic 'What about (read)' here:

http://www.alh.net/newlisp/phpbb/viewto ... string#375
What 'load' does is more or less this:

(eval-string (read-file "afile.lsp"))

The only difference is that 'load' will stream the file and at the same time evaluate, while the above example reads the whole file first into a string, then evaluates it.

'load' can stream very large files without a memory impact, because it evaluates s-expressions as they flow in, compiling and evaluating on the fly.

Lutz
Now with the new possibilitys of SQLite or other import function, which could give back huge strings, it might be usefull to have a command like 'eval-string' with the capabilitys of 'load'.Or is there no more difference between 'eval-string' and 'load' because memory impact has happened yet and it is nothing to optimise in 'eval-string'?
Hans-Peter

HPW
Posts: 1377
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

I made a test:

Code: Select all

> (time(load "C:/Dba/test.lsp"))
125
> (time(eval-string (read-file "C:/Dba/test.lsp")))
140
> (time(setq a (read-file "C:/Dba/test.lsp")))
0
> (time(eval-string a))
125
> (time(eval-string a))
141
> (time(eval-string a))
141
> (time(eval-string a))
141
> (time(eval-string a))
141
> (time(eval-string a))
125
> (time(eval-string a))
125
> (time(eval-string a))
141
> (time(eval-string a))
141
> (time(eval-string a))
140
> (time(eval-string a))
140
> (time(eval-string a))
125
>  
The file is a assoc-tab with 750 KB.
I should have made the test before posting.
So its seems not much overhead.
But why does 'eval-string' need different times on subsequent calls.
Hans-Peter

Lutz
Posts: 5282
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The smallest time fraction Windows can distinguish is ~16ms, that it, why it flips between 125 and 141. For a better estimate do the following:

(time (dotimes (x 100) (read-file "C:/Dba/test.lsp")))

the overhead of 'dotimes' is very small.

Speed wise I don't think that there is adifference streaming a file for evaluation by load or loading in to a buffer first, than evaluating. The memory impact when using SQLite already happened when it returns the string to to you.

Lutz

Post Reply