Operating Overhead: at Smalltalk (specifically Squeak)

How much slower can I reasonably expect to perform:be than to send a literal message on average? Should I avoid sending perform:in a loop, similar to the warning provided by Perl / Python programmers, to avoid calling eval("...")( Compiler evaluate:in Smalltalk) in a loop?

I focus mainly on Squeak, but I am also interested in other Smalltalks. Also, the overhead is higher with options perform:with:? thank you

+5
source share
2 answers

#perform:not like eval(). The problem with eval()(in terms of performance, anyway) is that it should compile the code that you send at runtime, which is a very slow operation. Smalltalk #perform:, on the other hand, is equivalent to Ruby send()or Objective-C performSelector:(in fact, both of these languages ​​were strongly inspired by Smalltalk). Languages ​​such as these are already looking for methods based on their name — they #perform:simply let you specify a name at runtime rather than recording time. It does not need to parse any syntax or compile anything like that eval().

( ), eval(). , perform:whatever. Squeak , .

+8

( Smalltalk/X, , - , ):

"foo" "foo:" - noops (.. a ^ self):

self foo                               ...  3.2 ns
self perform:#foo                      ...  3.3 ns
[self foo] value                       ... 12.5 ns (2 sends and 2 contexts)
[ ] value                              ...  3.1 ns (empty block)
Compiler valuate:('TestClass foo')     ...  1.15 ms

self foo:123                           ...  3.3 ns
self perform:#foo: with:123            ...  3.6 ns
[self foo:123] value                   ...   15 ns (2 sends and 2 contexts)
[self foo:arg] value:123               ...   23 ns (2 sends and 2 contexts)
Compiler valuate:('TestClass foo:123') ...  1.16 ms

":" ":"; - , (-), ( ) , , . IDE fileIn ; , .. , eval - , , .

Dell Vostro; , . , ; , 10 , OS/// . , . ( Repeat-arg ):

callFoo2
    |t1 t2|

    t1 :=
        TimeDuration toRun:[
            100000000 timesRepeat:[]
        ].

    t2 :=
        TimeDuration toRun:[
            100000000 timesRepeat:[self foo:123]
        ].

    Transcript showCR:t2-t1

EDIT: PS: : IDE (.. -). ( stc-), , (20-30%) - - .

EDIT: , (8ns , 9ns ). -, ( ) - .

+2

All Articles