[Newbies] Efficiently writing to a file

Bert Freudenberg bert at freudenbergs.de
Sun Apr 8 20:17:48 UTC 2007


On Apr 8, 2007, at 21:13 , Ian Oversby wrote:

> Is this a reasonable way of writing to a file?  It seems to run a
> little slower than I would expect.
>
> Thanks,
>
> Ian
>
> | myFile |
> myFile := StandardFileStream fileNamed: 'c:/test.txt'
>
> Transcript show: (Time millisecondsToRun: [
>    1 to: 10000 do: [
> 	    :x | myFile nextPutAll: ((x asString) , String crlf)
> 	]]) asString , ' millseconds' ; cr.
>
> myFile close.

It is unbuffered. Write to an in-memory stream first and then put the  
whole thing into the file.

- Bert -




More information about the Beginners mailing list