Loops in Smalltalk
kennethjohnsen at mail.dk
Sun Jun 27 17:33:10 UTC 2004
Colin Putney wrote:
> 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:
>> | anInt |
>> ^ Time
>> millisecondsToRun: [1
>> to: 5000
>> do: [:z |
>> self instancevar: z.
>> anInt := self instancevar.
>> Transcript show: anInt printString;
>> 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.
50000 takes 14 ms in Squeak. So something is going on anyways.
Btw. VisualWorks does 50000 in 1 ms, and 500000 in 9 ms :-)
More information about the Squeak-dev