[Newbies] Efficiently writing to a file

Ramon Leon ramon.leon at allresnet.com
Tue Apr 10 21:54:22 UTC 2007


> 
> Okay, I tried this and it still seems a bit slow:
> 
> | myFile ios |
> 
> ios := ReadWriteStream on: ''.
> 
> Transcript show: 'Populate Buffer: ',
> 	(Time millisecondsToRun: [
> 		1 to: 10000 do: [
> 			:x | ios nextPutAll: ((x asString) , 
> String crlf)
> 			]]) asString , ' millseconds' ; cr.
> 
> Transcript show: 'Position: ', (ios position) asString ; cr.
> 
> myFile := StandardFileStream fileNamed: 'c:/test.txt'.
> 
> Transcript show: 'Output Buffer: ',
>                     (Time millisecondsToRun: [
> 	myFile nextPutAll: (ios contents)]) asString,
>      ' milliseconds' ; cr.
> 
> myFile close.
> 
> # --
> 
> Populate Buffer is showing ~350 milliseconds to run on my 
> system whereas similar code in Perl is showing around 70 
> milliseconds.  Is this the correct way to use the stream?
> 
> Thanks,
> 
> Ian
> 
> On 08/04/07, Bert Freudenberg <bert at freudenbergs.de> wrote:
> >

Try taking out the Transcript show's from inside the loop, that's very slow.


Ramon Leon
http://onsmalltalk.com



More information about the Beginners mailing list