On 12 November 2010 15:24, Levente Uzonyi leves@elte.hu wrote:
On Fri, 12 Nov 2010, Igor Stasenko wrote:
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)
Single measurement is probably inaccurate. This benchmark creates lots of blocks, which means GC noise. The size of the "object table" is too small to be realistic, this hides cache related performance hits. Why don't you use an Array instead of Wrapper? IIRC Cog has optimization for the #at: primitive, also Arrays are compact. Why do you send #yourself and #timesRepeat:? You should slightly shuffle the objects to be more realistic about cache usage.
I'm inviting you to make own version of benchmark, which could simulate an extra level of indirection for accessing object field(s).
actually i was trying: t1 := [ 100000 timesRepeat: [ objects do:[ :each | each yourself ] ] vs t2 := [ 100000 timesRepeat: [ objects do:[ :each | each object ] ]
where #yourself there is to compensate an extra message send (#object), so it will compare 'read nothing, return self' , and 'read ivar', which is an indirection. But what i found that this gives no difference, and actually t2 < t1 sometimes :)
Levente
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.