Writing a large Collection of integers to a file fast

Zulq Alam me at zulq.net
Mon Jan 28 05:48:01 UTC 2008

Lukas Renggli wrote:
> Or even smarter:
>     aStream print: int; nextPut: Character cr
> Lukas

I tried this and didn't get the improvement I was expecting, < 2%. I had 
a deeper look and noticed Integer>>#printOn:base: generates an 
unnecessary string representation which it then reverses and prints to 
the stream.

I got closer to 20% with these changes to Integer as well:

printOn: aStream base: base
   self negative ifTrue: [aStream nextPut: $-].
   self abs normalize printDigitsOn: aStream base: base.

printDigitsOn: aStream base: base
   (self >= base)
       [(self // base) printDigitsOn: aStream base: base].

   aStream nextPut: (Character digitValue: self \\ base)

I'm not sure why one needs to send #normalize but it was being send 

I'll create an entry in Mantis when I get a moment to check the unit 
tests and the other printXXX methods on Integer.


More information about the Squeak-dev mailing list