On 20 Mar 2018, at 12:56, Henrik Sperre Johansen <henrik.s.johansen@veloxit.no> wrote:
This is great! And, +1 on the need for some more convenience constructors...
Word of warning (which would be nice to mention in the guide); using writeStreamDo: and manually constructed buffered writers will not #flush the buffered stream automatically on close, so it's crucial this is done manually.
Yes, you are right, but it is clearly documented in the class comment of ZnBufferedWriteStream There is also ZnBufferedWriteStream class>>#on:do: to help Now, these are system classes more than user classes. Normal users should get a ready made stream not knowing much about the construction process.
charGen := Random seed: 16543986234. output := String new: 1024*1024*50. 1 to: output size do: [ :ix | output at: ix put: ((charGen nextInt: 256) - 1) asCharacter ].
[(File named: 'utf16test.txt') writeStreamDo: [:ws | |encStream| encStream := ZnCharacterWriteStream on: (ZnBufferedWriteStream on: ws) encoding: 'utf16'. encStream nextPutAll: output ]] timeToRun.
FileSize: 102 336 KB.
[(File named: 'utf16test2.txt') writeStreamDo: [:ws | |encStream| encStream := ZnCharacterWriteStream on: (ZnBufferedWriteStream on: ws) encoding: 'utf16'. encStream nextPutAll: output;flush ]] timeToRun.
FileSize: 102 400 KB.
It's about 4 times slower than the corresponding
[FileStream forceNewFileNamed: 'utf16test2.txt' do: [:ws | ws converter: UTF16TextConverter new. ws nextPutAll: output ]] timeToRun
but it's 100MB of UTF16, and 4 secs vs 1, so probably not relevant to real use cases .
Ah, but you are cheating (deliberately or not ;-). Your test string is a ByteString not a WideString, and UTF16TextConverter contains a fast path that basically does nothing. Try another string, like 1 to: output size do: [ :ix | output at: ix put: ((charGen nextInt: 1024) - 1) asCharacter ]. Zn is the same speed, the old one does not even stop for me. I am not sure we have to optimise UTF16, maybe ... adding the same fast path would not be too difficult I guess.
Another addition to the guide valuable to those of use still stuck in the stone age, would be code equivalents to FileStream methods: forceNewFileNamed:do: newFileNamed:do: oldFileNamed:do:
Cheers, Henry
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html