Writing a large Collection of integers to a file fast

Lukas Renggli renggli at gmail.com
Sat Jan 26 11:49:39 UTC 2008


> Oe possible optimization is to not use the #, message  because it
> create a copy of the String.
> So you can try:
>
> aFile := CrLfFileStream fileNamed: aFilename.
> aLargeCollection do: [ :int |
>   aFile nextPutAll: int printString; nextPut: Character cr.
> ].
> aFile close.

Or even smarter:

    aStream print: int; nextPut: Character cr

Lukas


>
>
> On Jan 26, 2008, at 12:37 PM, André Wendt wrote:
>
> > Hi,
> >
> > I'm looking for a fast way to write a large Collection of ints (over 6
> > million elements) to a file. My attempt was:
> >
> > aFile := CrLfFileStream fileNamed: aFilename.
> > aLargeCollection do: [ :int |
> >  aFile nextPutAll: int printString, String cr.
> > ].
> > aFile close.
> >
> > Unfortunately, this takes more than fifteen minutes. I suspect this is
> > due to my implementation.
> >
> > Is there any smart way I can do this faster?
> >
> > Thanks,
> > André
> >
>
>         Mth
>
>
>
>
>


-- 
Lukas Renggli
http://www.lukas-renggli.ch



More information about the Squeak-dev mailing list