[Pharo-project] could we agree to remove caseOf: and caseOf:otherwise:
siguctua at gmail.com
Sun Feb 13 04:02:23 CET 2011
On 13 February 2011 02:58, Levente Uzonyi <leves at elte.hu> wrote:
> On Sun, 13 Feb 2011, Igor Stasenko wrote:
>> Please read the Ian's paper about switch statement vs message sends..
>> You will discover something surprising for you.
> Link please?
Lastly, we implemented the example presented in Section
2 of this paper: data structures suitable for a Lisp-like
language. We implemented a ‘traditional’ length primitive
using a switch on an integer tag to select the appropriate
implementation amongst a set of possible case labels.
This was compared with an implementation in which data
was stored using our object model and the length primitive
used send to invoke a method in the objects themselves.7
Both were run for one million iterations on forty objects, ten
each of the four types that support the length operation.
The results, with varying degrees of object model optimisations
implementation time % of switch
switch-based 503 ms 100.0%
dynamic object-based 722 ms 69.7%
+ global cache 557 ms 90.3%
+ inline cache 243 ms 207.0%
This shows that an , object-based implementation
can perform at better than half the speed of a typical C implementation
for a simple language primitive. With a global
method cache (constant overhead, no matter how many
method invocation sites exist) the performance is within
10% of optimised C. When the inline cache was enabled
the performance was better than twice that of optimised C.
Igor Stasenko AKA sig.
More information about the Pharo-project