Loops in Smalltalk

Colin Putney cputney at wiresong.ca
Sun Jun 27 17:17:22 UTC 2004


On Jun 27, 2004, at 11:49 AM, Kenneth Johnsen wrote:

> I read an article about the new version of Dataflex, where it said 
> that the time it took to do 5000 get/set operations had been reduced 
> from 58 to 3 seconds.
>
> I read it like: set and get an instance variable on an object 5000 
> times, but I presume that something more advanced is going on 
> (otherwise, it's not that impressive).
>
> But this got me wondering: how long does it take in Smalltalk?
>
> So, I made a small class, with one instance variable: instancevar, and 
> three methods: instancevar, instancevar: and runTest. The two former 
> just gets/sets instancevar, and runTest does:
>
> runTest
>    | anInt |
>    ^ Time
>        millisecondsToRun: [1
>                to: 5000
>                do: [:z |
>                    self instancevar: z.
>                    anInt := self instancevar.
>                    Transcript show: anInt printString;
>                         cr]]
>
> Now, I didn't have the "Transcript show" in it the first time I ran it.
>
> Squeak printed: 1
> Dolphin printed: 1
>
> Question 1: Very nice. But am I missing something, where the compiler 
> figures out that my instancevar is not used for anything else, and 
> ignores it?

Nah, it's just that Smalltalk can do 5000 get/sets in less than a 
millisecond. On your machine, anyway. Mine takes 3 milliseconds for 
this test. Try 50,000 iterations.

Colin







More information about the Squeak-dev mailing list