[r7647]: sandbox / jlf / samples / benchmark / doers-benchmark.rex  Maximize  Restore  History

Download this file

234 lines (190 with data), 6.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
trace A
count = 10
call run count, .context~package~findRoutine("emptyRoutine")
call run count, {/**/}
call run count, {::r}
call run count, .methods["EMPTYMETHOD"]
call run count, {::m}
-- Here, the coactivities are ended at first call, so very fast...
call run count, {::r.c}
-- for a coactive method, the self must be passed whith ~doer
call run count, {::m.c}~doer(.nil)
call run count, .context~package~findRoutine("myRoutine")
call run count, {if item // 1000 == 0 then call charout ,"."}
call run count, {::r if item // 1000 == 0 then call charout ,"."}
call run count, .methods["MYMETHOD"]
call run count, {::m if self // 1000 == 0 then call charout ,"."}
-- Current implementation of yield is very costly !
call run count, {::r.c do forever ; .yield[]; item = arg(1) ; if item // 1000 == 0 then call charout ,"." ; end}
call run count, {::m.c do forever ; .yield[]; item = arg(1) ; if item // 1000 == 0 then call charout ,"." ; end}~doer(.nil)
-- 4 times faster when using self~yield
call run count, .myCoactivity~new
trace O
--===========================================================================--
count = 200000
call time('r')
r = 0
do i=1 to count
r += 2 * i
end
say r count "loops, no call :" time('e')~format(2,4)
-------------------------------------------------------------------------------
call time('r')
r = 0
do i=1 to count
r += double(i)
end
say r "routine double, called" count "times :" time('e')~format(2,4)
-------------------------------------------------------------------------------
call time('r')
f = {return 2 * arg(1)}~doer
r = 0
do i=1 to count
r += f~do(i)
end
say r "literal {return 2 * arg(1)}~doer before loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
f = {return 2 * arg(1)}
r = 0
do i=1 to count
r += f~do(i)
end
say r "literal {return 2 * arg(1)} before loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
f = {return 2 * arg(1)}
r = 0
do i=1 to count
r += f~(i)
end
say r "literal {return 2 * arg(1)} before loop, called with ~()" count "times :" time('e')~format(2,4)
-------------------------------------------------------------------------------
call time('r')
r = 0
do i=1 to count
r += {return 2 * arg(1)}~do(i)
end
say r "literal {return 2 * arg(1)} in loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
r = 0
do i=1 to count
r += {return 2 * arg(1)}~(i)
end
say r "literal {return 2 * arg(1)} in loop, called with ~()" count "times :" time('e')~format(2,4)
-------------------------------------------------------------------------------
call time('r')
f = {:return 2 * arg(1)}
r = 0
do i=1 to count
r += f~do(i)
end
say r "literal {:return 2 * arg(1)} before loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
f = {:return 2 * arg(1)}
r = 0
do i=1 to count
r += f~(i)
end
say r "literal {:return 2 * arg(1)} before loop, called with ~()" count "times :" time('e')~format(2,4)
-------------------------------------------------------------------------------
call time('r')
r = 0
do i=1 to count
r += {:return 2 * arg(1)}~do(i)
end
say r "literal {:return 2 * arg(1)} in loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
r = 0
do i=1 to count
r += {:return 2 * arg(1)}~(i)
end
say r "literal {:return 2 * arg(1)} in loop, called with ~()" count "times :" time('e')~format(2,4)
-------------------------------------------------------------------------------
call time('r')
f = {::m return 2 * self}
r = 0
do i=1 to count
r += f~do(i)
end
say r "literal {::m return 2 * self} before loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
f = {::m return 2 * self}
r = 0
do i=1 to count
r += f~(i)
end
say r "literal {::m return 2 * self} before loop, called with ~()" count "times :" time('e')~format(2,4)
-------------------------------------------------------------------------------
call time('r')
r = 0
do i=1 to count
r += {::m return 2 * self}~do(i)
end
say r "literal {::m return 2 * self} in loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
r = 0
do i=1 to count
r += {::m return 2 * self}~(i)
end
say r "literal {::m return 2 * self} in loop, called with ~()" count "times :" time('e')~format(2,4)
-------------------------------------------------------------------------------
multiplier = 2
call time('r')
f = {::cl expose multiplier ; return multiplier * arg(1)}
r = 0
do i=1 to count
r += f~do(i)
end
say r "literal {::cl expose multiplier ; return multiplier * arg(1)} before loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
f = {::cl expose multiplier ; return multiplier * arg(1)}
r = 0
do i=1 to count
r += f~(i)
end
say r "literal {::cl expose multiplier ; return multiplier * arg(1)} before loop, called with ~()" count "times :" time('e')~format(2,4)
call time('r')
r = 0
do i=1 to count
r += {::cl expose multiplier ; return multiplier * arg(1)}~do(i)
end
say r "literal {::cl expose multiplier ; return multiplier * arg(1)} in loop, called with ~do" count "times :" time('e')~format(2,4)
call time('r')
r = 0
do i=1 to count
r += {::cl expose multiplier ; return multiplier * arg(1)}~(i)
end
say r "literal {::cl expose multiplier ; return multiplier * arg(1)} in loop, called with ~()" count "times :" time('e')~format(2,4)
say "Ended coactivities:" .Coactivity~endAll
-------------------------------------------------------------------------------
::routine run
use strict arg count, doer
call time('r')
call runN count, doer
mean = time('e')/count
say "mean="mean~format(2,4)
::routine runN
use strict arg count, doer
do count
call time('r')
10000~times(doer)
call charout ,time('e')~format(2,4)" "
end
::routine emptyRoutine
::routine double
return 2 * arg(1)
::method emptyMethod
::routine myRoutine
use strict arg item
if item // 1000 == 0 then call charout ,"."
::method myMethod
if self // 1000 == 0 then call charout ,"."
::class myCoactivity inherit Coactivity
::method main -- entry point
-- Here, self is the coactivity.
do forever
self~yield -- More efficient than .yield[], because no need to search for the current coactivity : it's self.
item = arg(1)
if item // 1000 == 0 then call charout ,"."
end
::options NOMACROSPACE
::requires "extension/extensions.cls"

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks