[Newbies] Efficiently writing to a file

Ian Oversby oversby at googlemail.com
Tue Apr 10 22:09:32 UTC 2007


I didn't know I was using Transcript in a loop.  Still, I've changed
it to append to a string instead of write to transcript and use print:
but now it is quoting the numbers which isn't quite what I'm after and
it still takes just as long.

| myFile ios s |

ios := ReadWriteStream on: ''.

s := 'Populate Buffer: ',
	(Time millisecondsToRun: [
		1 to: 10000 do: [
			:x | ios print: x. ios print: String crlf]]) asString
	, ' millseconds'.
	
Transcript show: s ; cr.
	
Transcript show: 'Position: ', (ios position) asString ; cr.

myFile := StandardFileStream fileNamed: 'c:/squeak/t1.txt'.

Transcript show: 'Output Buffer: ',
                   (Time millisecondsToRun: [
       myFile nextPutAll: (ios contents)]) asString,
    ' milliseconds' ; cr.

myFile close.

Here is the output:

Populate Buffer: 313 millseconds
Position: 78894
Output Buffer: 1 milliseconds

So it is writing to Output Buffer pretty quickly but not appending to
the stream.  Is there a profiler in Squeak I can search for the
problem myself with?

Ian

On 10/04/07, Ramon Leon <ramon.leon at allresnet.com> wrote:
> >
> > 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>


More information about the Beginners mailing list