42 "Created: / 31-05-2013 / 12:02:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
42 "Created: / 31-05-2013 / 12:02:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
43 ! ! |
43 ! ! |
44 |
44 |
45 !BenchmarkInstance methodsFor:'accessing'! |
45 !BenchmarkInstance methodsFor:'accessing'! |
46 |
46 |
47 benchmark |
|
48 ^ benchmarkSelector |
|
49 ! |
|
50 |
|
51 instance |
47 instance |
52 ^ instance |
48 ^ instance |
|
49 ! |
|
50 |
|
51 selector |
|
52 ^ benchmarkSelector |
53 ! ! |
53 ! ! |
54 |
54 |
55 !BenchmarkInstance methodsFor:'initialization'! |
55 !BenchmarkInstance methodsFor:'initialization'! |
56 |
56 |
57 class: class benchmark: benchmark |
57 class:class selector:benchmark |
58 self instance: class new benchmark: benchmark |
58 self instance:class new selector:benchmark |
59 |
59 |
60 "Created: / 27-05-2013 / 19:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
60 "Created: / 27-05-2013 / 19:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
61 ! |
61 ! |
62 |
62 |
63 instance: anObject benchmark: aSelector |
63 instance:anObject selector:aSelector |
64 | benchmarkMethod annotation | |
64 | benchmarkMethod annotation | |
65 (anObject respondsTo: aSelector) ifFalse:[ |
65 |
66 self error:'Object does not respond to benchmark (no ', anObject class printString , '>>', aSelector storeString. |
66 (anObject respondsTo:aSelector) ifFalse:[ |
67 ]. |
67 self |
68 |
68 error:'Object does not respond to benchmark (no ' |
|
69 , anObject class printString , '>>' |
|
70 , aSelector storeString. |
|
71 ]. |
69 instance := anObject. |
72 instance := anObject. |
70 benchmarkSelector := aSelector. |
73 benchmarkSelector := aSelector. |
71 |
74 instance class methodDictionary |
72 instance class methodDictionary keysAndValuesDo:[:selector :method | |
75 keysAndValuesDo:[:selector :method | |
73 method numArgs == 0 ifTrue:[ |
76 method numArgs == 0 ifTrue:[ |
74 (method pragmaAt: #setup) notNil ifTrue:[ |
77 (method pragmaAt:#setup) notNil ifTrue:[ |
75 setUpSelector1 notNil ifTrue:[ |
78 setUpSelector1 notNil ifTrue:[ |
76 self error: 'More than one <setup> method'. |
79 self error:'More than one <setup> method'. |
|
80 ]. |
|
81 setUpSelector1 := selector. |
77 ]. |
82 ]. |
78 setUpSelector1 := selector. |
83 (method pragmaAt:#teardown) notNil ifTrue:[ |
|
84 tearDownSelector1 notNil ifTrue:[ |
|
85 self error:'More than one <teardown> method'. |
|
86 ]. |
|
87 tearDownSelector1 := selector. |
|
88 ]. |
|
89 (method pragmaAt:#warmup) notNil ifTrue:[ |
|
90 warmUpSelector1 notNil ifTrue:[ |
|
91 self error:'More than one <warmup> method'. |
|
92 ]. |
|
93 warmUpSelector1 := selector. |
|
94 ]. |
79 ]. |
95 ]. |
80 (method pragmaAt: #teardown) notNil ifTrue:[ |
96 ]. |
81 tearDownSelector1 notNil ifTrue:[ |
97 benchmarkMethod := instance class compiledMethodAt:benchmarkSelector. |
82 self error: 'More than one <teardown> method'. |
98 annotation := benchmarkMethod pragmaAt:#setup:. |
83 ]. |
|
84 tearDownSelector1 := selector. |
|
85 ]. |
|
86 (method pragmaAt: #warmup) notNil ifTrue:[ |
|
87 warmUpSelector1 notNil ifTrue:[ |
|
88 self error: 'More than one <warmup> method'. |
|
89 ]. |
|
90 warmUpSelector1 := selector. |
|
91 ]. |
|
92 ]. |
|
93 ]. |
|
94 |
|
95 benchmarkMethod := instance class compiledMethodAt: benchmarkSelector. |
|
96 |
|
97 annotation := benchmarkMethod pragmaAt: #setup:. |
|
98 annotation notNil ifTrue:[ |
99 annotation notNil ifTrue:[ |
99 | method selector | |
100 | method selector | |
100 selector := annotation argumentAt: 1. |
101 |
|
102 selector := annotation argumentAt:1. |
101 selector isSymbol ifFalse:[ |
103 selector isSymbol ifFalse:[ |
102 self error: '<setup:> annotation argument not a symbol'. |
104 self error:'<setup:> annotation argument not a symbol'. |
103 ]. |
105 ]. |
104 method := instance compiledMethodAt: selector ifAbsent: [nil]. |
106 method := instance compiledMethodAt:selector ifAbsent:[ nil ]. |
105 method isNil ifTrue:[ |
107 method isNil ifTrue:[ |
106 self error: '<setup:> method does not exist (', selector,')'. |
108 self error:'<setup:> method does not exist (' , selector , ')'. |
107 ]. |
109 ]. |
108 method numArgs ~~ 0 ifTrue:[ |
110 method numArgs ~~ 0 ifTrue:[ |
109 self error: '<setup:> method has arguments (', selector,')'. |
111 self error:'<setup:> method has arguments (' , selector , ')'. |
110 ]. |
112 ]. |
111 setUpSelector2 := selector. |
113 setUpSelector2 := selector. |
112 ]. |
114 ]. |
113 |
115 annotation := benchmarkMethod pragmaAt:#teardown:. |
114 annotation := benchmarkMethod pragmaAt: #teardown:. |
|
115 annotation notNil ifTrue:[ |
116 annotation notNil ifTrue:[ |
116 | method selector | |
117 | method selector | |
117 selector := annotation argumentAt: 1. |
118 |
|
119 selector := annotation argumentAt:1. |
118 selector isSymbol ifFalse:[ |
120 selector isSymbol ifFalse:[ |
119 self error: '<teardown:> annotation argument not a symbol'. |
121 self error:'<teardown:> annotation argument not a symbol'. |
120 ]. |
122 ]. |
121 method := instance compiledMethodAt: selector ifAbsent: [nil]. |
123 method := instance compiledMethodAt:selector ifAbsent:[ nil ]. |
122 method isNil ifTrue:[ |
124 method isNil ifTrue:[ |
123 self error: '<teardown:> method does not exist (', selector,')'. |
125 self error:'<teardown:> method does not exist (' , selector , ')'. |
124 ]. |
126 ]. |
125 method numArgs ~~ 0 ifTrue:[ |
127 method numArgs ~~ 0 ifTrue:[ |
126 self error: '<teardown:> method has arguments (', selector,')'. |
128 self error:'<teardown:> method has arguments (' , selector , ')'. |
127 ]. |
129 ]. |
128 tearDownSelector2 := selector. |
130 tearDownSelector2 := selector. |
129 ]. |
131 ]. |
130 |
132 annotation := benchmarkMethod pragmaAt:#warmup:. |
131 annotation := benchmarkMethod pragmaAt: #warmup:. |
|
132 annotation notNil ifTrue:[ |
133 annotation notNil ifTrue:[ |
133 | method selector | |
134 | method selector | |
134 selector := annotation argumentAt: 1. |
135 |
|
136 selector := annotation argumentAt:1. |
135 selector isSymbol ifFalse:[ |
137 selector isSymbol ifFalse:[ |
136 self error: '<warmup:> annotation argument not a symbol'. |
138 self error:'<warmup:> annotation argument not a symbol'. |
137 ]. |
139 ]. |
138 method := instance compiledMethodAt: selector ifAbsent: [nil]. |
140 method := instance compiledMethodAt:selector ifAbsent:[ nil ]. |
139 method isNil ifTrue:[ |
141 method isNil ifTrue:[ |
140 self error: '<warmup:> method does not exist (', selector,')'. |
142 self error:'<warmup:> method does not exist (' , selector , ')'. |
141 ]. |
143 ]. |
142 method numArgs ~~ 0 ifTrue:[ |
144 method numArgs ~~ 0 ifTrue:[ |
143 self error: '<warmup:> method has arguments (', selector,')'. |
145 self error:'<warmup:> method has arguments (' , selector , ')'. |
144 ]. |
146 ]. |
145 warmUpSelector2 := selector. |
147 warmUpSelector2 := selector. |
146 ]. |
148 ]. |
147 |
149 |
148 "Created: / 27-05-2013 / 19:06:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
150 "Created: / 27-05-2013 / 19:06:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |