[Vm-dev] Direct object pointers vs indirect ones pros and cons

Igor Stasenko siguctua at gmail.com
Fri Nov 12 09:58:59 UTC 2010


Here a 'simulated' kind of indirect pointers.

The Wrapper class having an 'object' ivar
and in this way, we simulating indirection.


| objects wrapped t1 t2 t3 |
objects := (1 to: 1000) collect: [:i | Object new ].
wrapped := objects collect: [:each | Wrapper new object: each ].

t1 := [ 100000 timesRepeat: [ objects do:[ :each |  each yourself ] ]
] timeToRun.
t2 := [ 100000 timesRepeat: [ wrapped do:[ :each |  each object
yourself ] ] ] timeToRun.
t3 := [ 100000 timesRepeat: [ wrapped do:[ :each |  ] ] ] timeToRun.
{t1. t2. t3}

Running on Cog it gives:

 #(3241 3498 2793)

the first bench is kind-of 'measure time to access directly to objects'
the second one is 'measure indirect access'
and third is measure a loop overhead.

So, by taking this naive benchmark, we got:

(3498 - 2793) / (3241 - 2793) asFloat
1.573660714285714

so, 50% slower.

But actually this benchmarks shows a cost of extra message send rather
than impact of extra level of indirection.
Well, a message is a kind of indirection..  :)

-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Vm-dev mailing list