[Vm-dev] Re: [squeak-dev] Squeak vs Python "smack down"

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Feb 8 20:03:39 UTC 2011


2011/2/8 Eliot Miranda <eliot.miranda at gmail.com>:
>
>
>
> On Tue, Feb 8, 2011 at 5:01 AM, Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com> wrote:
>>
>> 2011/2/8 Levente Uzonyi <leves at elte.hu>:
>> >
>> > On Tue, 8 Feb 2011, Nicolas Cellier wrote:
>> >
>> >>
>> >> Just a detail, Python range(a,b) are semi open [a,b)
>> >> think like C for(i=0;i<n; i++)
>> >>
>> >> In the Smalltalk proc8:withwith:with:with:: the range was interpreted as [a,b].
>> >> This Smalltalk (and Cog) unfairly perform too much work.
>> >
>> > And there's another one. In #proc0:block: the loops are (1 to: loops) do: instead of 1 to: loops do:.
>> >
>> >
>> > Levente
>> >
>>
>> Yes I noticed, but empty loop time is subtracted.
>> I wonder if it makes a difference.
>
> There is a huge difference between 1 to: loops do: [:i|] and (1 to: loops) do: [:i|].  IIRC the empty block is written as 1 to: loops do: [:i|].
> SimpleStackBasedCogit:
> Time millisecondsToRun:
> [| loops |
> loops := 100000000.
> 1 to: loops do: [:i|]] 757
> Time millisecondsToRun:
> [| loops |
> loops := 100000000.
> (1 to: loops) do: [:i|]] 16953
> StackToRegisterMappingCogit
> Time millisecondsToRun:
> [| loops |
> loops := 100000000.
> 1 to: loops do: [:i|]] 244
> Time millisecondsToRun:
> [| loops |
> loops := 100000000.
> (1 to: loops) do: [:i|]] 17149
>

I was more after the difference with empty loops, like:

[| loops x |
loops := 10000000.
x := 1.
(1 to: loops) do: [:i| x := x + 1. x squared]]  timeToRun
-
[| loops |
loops := 10000000.
(1 to: loops) do: [:i| ]]  timeToRun
 5405 5397


[| loops x |
loops := 10000000.
x := 1.
1 to: loops do: [:i| x := x + 1. x squared]]  timeToRun
-
[| loops |
loops := 10000000.
1 to: loops do: [:i| ]]  timeToRun
 5272 5205

Nicolas


More information about the Vm-dev mailing list