eval-stream?

Started by HPW, January 12, 2004, 10:45:05 PM

Previous topic - Next topic

HPW

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



http://www.alh.net/newlisp/phpbb/viewtopic.php?p=375&highlight=evalstring#375">http://www.alh.net/newlisp/phpbb/viewto ... string#375">http://www.alh.net/newlisp/phpbb/viewtopic.php?p=375&highlight=evalstring#375


Quote
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

#1
I made a test:

> (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

#2
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