Hello all.
Here's a question. I take the code '1000 factorial' and do it. It takes 35 milliseconds (using Time MillisecondsToRun). When I take the same code and 'print it', it takes about 9500 milliseconds. This is two orders of magnatude slower!
Why? Are not the same objects created, with the printing version just printing an ASCII representation of the final end product Object?
Thanks!
Timothy Reaves treaves@silverfields.com is widely believed to have written:
Hello all.
Here's a question. I take the code '1000 factorial' and do it. It takes 35 milliseconds (using Time MillisecondsToRun). When I take the same code and 'print it', it takes about 9500 milliseconds. This is two orders of magnatude slower!
Why? Are not the same objects created, with the printing version just printing an ASCII representation of the final end product Object?
Nope. To print it, you have to generate the string representation (take a look at the codefor Integer> printString) then insert it into the current text view's selection. This involves formatting it to wrap properly etc, then actually displaying it and then updating the screen. 1000 factorial has 2568 characters, which takes some work to wrap neatly.
tim
On Thursday 02 August 2001 07:25 pm, you wrote:
Hello all.
Here's a question. I take the code '1000 factorial' and do it. It takes 35 milliseconds (using Time MillisecondsToRun). When I take the same code and 'print it', it takes about 9500 milliseconds. This is two orders of magnatude slower!
Why? Are not the same objects created, with the printing version just printing an ASCII representation of the final end product Object?
Well, kinda. There's four things going on here (with timings on my machine):
* computing the number (43 msec) * changing this LargeInteger into a string (via printString) (7922 msec) 99.8% of that time is spent in LargePositiveInteger>>printOn:base: * sending it to the Transcript (3 msec) * displaying it (flushing) the transcript (100 msec)
As you see, the bulk of the work is computing the printString.
squeak-dev@lists.squeakfoundation.org