You can find the code below. I just change the call to m by m1 to test the two methods.
I started again in a fresh pharo 6 image and now the results seem all similar for the following code. I will do all my tests again to see if it was my fault but it takes a lot of time (2 hours for each full test). What sould be the expected results ? Should an instance of an anonymous class be as fast as a regular instance when calling the same code, being defined in the anon class or its super class ? A implements m ^100 printString and B subclass of A implements m1 ^100 printString a := B new. class := A newAnonymousSubclass addSlot: (InstanceVariableSlot named: #y); compile: 'm1 ^100 printString'; yourself. c := A new becomeForward: class new. res := Dictionary new. col1 := OrderedCollection new. col2 := OrderedCollection new. 10000 timesRepeat: [ Smalltalk garbageCollect . col1 add: [1000000 timesRepeat: [ a m ]] timeToRun]. 10000 timesRepeat: [ Smalltalk garbageCollect . col2 add: [1000000 timesRepeat: [ c m ]] timeToRun]. res at: 'a' put: col1. res at: 'c' put: col2. res inspect Steven. Le 2017-06-16 17:31, Denis Kudriashov a écrit : > Hi Steven. > > Could you show code which you measure? > > 2017-06-16 17:17 GMT+02:00 Steven Costiou <steven.cost...@kloum.io>: > >> I have been playing a bit with anonymous subclasses, and instances of anon >> subclasses seem slower to execute code than "regular" subclasses instances, >> but sometimes they reach equivalent performances (for code defined in >> anon-subclasses). I don't understand why. >> >> I have a class A with a method m. >> B is subclass of A with a new method m1. >> Anon-A is an anonymous class of A which also implements the m1 method. >> >> I did various tests of speed and: >> >> - when executing m, compiled in A, instances of Anon-A are around 10% slower >> than instances of B >> >> - when executing m1, compiled in B and in Anon-A, performances are >> equivalent between instances of B and of anon-A >> >> Is that a particular behavior of anonymous subclasses, like their instances >> can easily find behavior defined in their class but have to perform >> extra-work to find methods defined in their superclass (which is not >> anonymous) ? Is that vm related ? Other ? >> >> Steven.