Writing a large Collection of integers to a file fast
Klaus D. Witzel
klaus.witzel at cobss.com
Sat Jan 26 17:31:06 UTC 2008
If you have only small integers and free memory, the fastest method (just
one i/o) would be
| memory fOut |
memory := Bitmap new: 6 * 1000 * 1000.
memory atAllPut: SmallInteger maxVal.
[(fOut := StandardFileStream newFileNamed: 'f.out')
nextPutAll: memory asByteArray]
ensure: [fOut close]
You can fill the memory instance with #integerAt:put:
/Klaus
On Sat, 26 Jan 2008 16:57:16 +0100, André Wendt wrote:
> Lukas Renggli wrote:
>>> 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
>
> Thanks for your suggestions! I've tried, but it didn't give the boost I
> was hoping for...
>
> André
>
>>> 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
>
>
>
More information about the Squeak-dev
mailing list
|