Integer micro-benchmarks

David Simmons pulsar at qks.com
Wed Apr 25 23:50:11 EDT 2001


"Steve Wart" <swart at deadspam.com> wrote in message
news:5MLF6.98590$166.1840160 at news1.rdc1.bc.home.com...
> Here is some more silliness.
>
> If you take the #triangle method and turn it into a block closure, as
below,
> in VW it takes almost 10 seconds (on my 333 PII)

Really!  10 seconds versus 7 seconds?

SIDEBAR: Man squeak sucks idle/cpu cycles.  I just downloaded squeak. I left
it open and tried to run a benchmark in something else. It skewed the
benchmark by 25%.

Hmm. Ok, I quit squeak.

The execution time difference for SmallScript was around 4% relative to
having the <result> variable be local to the block. Internally the
difference is the direct result of the JIT not making the extra effort to
avoid redundant load/store access on an multi-level indirection of a shared
variable.

I guess that's not so surprising. Over the years I've been very aggressive
in having both the Smalltalk compiler and the VM optimize
closures/continuations, and related exception/curtailing scenarios.

Good goobley goo. I just ran it on VW and got the times:

1784ms for 9,000,000 loops using <result> local to the block.

4102ms for 9,000,000 loops using <result> as a method temp (shared with the
block).

The same runs on SmallScript were:
1313ms vs 1380ms respectively

NOTE: This is the exact same hardware on ran the previously posted tests on.

-- Dave S.

>
> "c.l.s. benchmark"
> |sum time triangle result |
> sum := 0.
> triangle := [ :int|
>  result := 0.
>  1 to: int do: [ :i | result := result + i].
>  result ].
>
> time := Time millisecondsToRun: [
> 10000000 timesRepeat: [
> sum := sum + (triangle value: 10)]].
> ^Array with: sum with: time.
>
> If you modify the above code so that the "result" instance variable is a
> block temp, i.e.
>
> triangle := [ :int| | result |
>  result := 0.
>  1 to: int do: [ :i | result := result + i].
>  result ].
>
> It executes in under 7 seconds (same as if #triangle were a method on
> Integer).
>
> Something to do with the reification of the block temp I suppose [I only
> know about this from reading a post by Allen Wirfs-Brock on the Squeak
list
> this am] :) Smalltalk MT does not allow block temps.
>
> Does python have closures? That would be interesting to see.
>
> Cheers,
> Steve





More information about the Python-list mailing list