Urs Hoelzle urs at
Thu Aug 31 08:43:05 UTC 1995

Rainer Blome wrote:

> > You can get 90% of 'if bool then else':
> > if: bool Then: thenClause Else: elseClause = 
> >    ( bool if: thenClause False: elseClause ).
> Oh, OK.  In this case, a macro would indeed be an efficiency hack.  Because
> using a message would give up locality there.  Where is the `if:Then:Else:'
> slot?  In globalBehavior, I guess.  And that slot takes time to find.  If
> its content is a normal method, it will be evaluated over and over again.
> Maybe the compiler can optimize that away, but I don't think so.

Well, I couldn't let *that* bait go :-) Here's a little experiment:
put the if: .. method in defaultBehavior and create a test object
called foo containing

(| parent* = defaultBehavior*.
   test:  n With: x With: y = ( n do: [     x < y ifTrue: 'true' False: 'false'] ).
   test2: n With: x With: y = ( n do: [ if: x < y Then:   'true' Else:  'false'] ).

[Hint: never put such testing code in the shell, because it has a
dynamic parent that can mess up performance.]

On my system, [foo test:  100000 With: 3 With: 4] time is 135..161   and
              [foo test2: 100000 With: 3 With: 4] time is 137..162.

No difference.

Of course, a *really* smart compiler would execute both in 0 ms, but
that's another story.


More information about the Self-interest mailing list