thanks added to http://code.google.com/p/pharo/issues/detail?id=2885 Stef On Aug 31, 2010, at 12:22 AM, Levente Uzonyi wrote:
In Squeak(CogVM): "7-bit ByteString" mediumDoc := ByteString new: 4096 streamContents: [ :stream | 4096 timesRepeat: [ stream nextPut: (Character value: 128 atRandom - 1) ] ]. (1 to: 5) collect: [ :run | [ 1 to: 100000 do: [ :ix | mediumDoc squeakToUtf8 ] ] timeToRun ]. "===> #(344 345 344 347 344)" (1 to: 5) collect: [ :run | [ 1 to: 100000 do: [ :ix | mediumDoc convertToWithConverter: UTF8TextConverter new ] ] timeToRun ]. "===> #(404 373 375 374 374)" (1 to: 5) collect: [ :run | [ 1 to: 100000 do: [ :ix | mediumDoc convertToEncoding: 'utf-8' ] ] timeToRun ]. "===> #(1443 1440 1438 1443 1445)"
"7-bit ByteString with a single 8-bit character" mediumDoc := ByteString new: 4096 streamContents: [ :stream | 4096 timesRepeat: [ stream nextPut: (Character value: 128 atRandom - 1) ] ]. mediumDoc at: 2048 put: (Character value: 128). (1 to: 5) collect: [ :run | [ 1 to: 100000 do: [ :ix | mediumDoc squeakToUtf8 ] ] timeToRun ]. "===> #(1262 1246 1249 1250 1249)." (1 to: 5) collect: [ :run | [ 1 to: 100000 do: [ :ix | mediumDoc convertToWithConverter: UTF8TextConverter new ] ] timeToRun ]. "===> #(1261 1256 1264 1260 1258)" (1 to: 5) collect: [ :run | [ 1 to: 100000 do: [ :ix | mediumDoc convertToEncoding: 'utf-8' ] ] timeToRun ]. "===> #(2591 2567 2538 2543 2582) Not neglible (~0.5 speed)"
"8-bit ByteStrings (only 1000 conversion/test)" mediumDoc := ByteString new: 4096 streamContents: [ :stream | 4096 timesRepeat: [ stream nextPut: (Character value: 256 atRandom - 1) ] ]. (1 to: 5) collect: [ :run | [ 1 to: 1000 do: [ :ix | mediumDoc squeakToUtf8 ] ] timeToRun ]. "===> #(627 618 618 622 618)" (1 to: 5) collect: [ :run | [ 1 to: 1000 do: [ :ix | mediumDoc convertToWithConverter: UTF8TextConverter new ] ] timeToRun ]. "===> #(648 621 620 621 622)" (1 to: 5) collect: [ :run | [ 1 to: 1000 do: [ :ix | mediumDoc convertToEncoding: 'utf-8' ] ] timeToRun ]. "===> #(676 653 650 658 648)"
"WideStrings" mediumDoc := String new: 4096 streamContents: [ :stream | 4096 timesRepeat: [ stream nextPut: (Character value: (1<<22) atRandom - 1) ] ]. (1 to: 5) collect: [ :run | [ 1 to: 1000 do: [ :ix | mediumDoc squeakToUtf8 ] ] timeToRun ]. "===> #(632 635 633 632 633)" (1 to: 5) collect: [ :run | [ 1 to: 1000 do: [ :ix | mediumDoc convertToWithConverter: UTF8TextConverter new ] ] timeToRun ]. "===> #(693 625 625 626 625)" (1 to: 5) collect: [ :run | [ 1 to: 1000 do: [ :ix | mediumDoc convertToEncoding: 'utf-8' ] ] timeToRun ]. "===> #(644 637 640 640 638)"
So, for 7-bit ByteStrings (optionally with few 8-bit characters), it does make a difference to use #squeakToUtf8, for 8-bit ByteStrings and WideStrings it doesn't really matter.