-
Notifications
You must be signed in to change notification settings - Fork 21
/
benchmark.js
438 lines (241 loc) · 12 KB
/
benchmark.js
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
const b = require('benny'),
jssm = require('../../dist/jssm.es5.cjs'),
sm = jssm.sm;
const Tl4 = sm`red => green => yellow => red; [red yellow green] ~> off -> red;`;
function TransitionCycleTL100Times() {
for (let i=0; i<100; ++i) {
Tl4.transition('green');
Tl4.transition('yellow');
Tl4.transition('red');
}
}
const Tl4WH = sm`red => green => yellow => red; [red yellow green] ~> off -> red;`;
Tl4WH.set_hook({ from: 'red', to: 'green', handler: () => true, kind: 'hook' });
function TransitionCycleTLWithHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4WH.transition('green');
Tl4WH.transition('yellow');
Tl4WH.transition('red');
}
}
const Tl4WAHA = sm`red 'foo' => green => yellow => red; [red yellow green] ~> off -> red;`;
Tl4WAHA.set_hook({ from: 'red', to: 'green', name: 'foo', handler: () => true, kind: 'named' });
function TransitionCycleTLWithNamedHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4WAHA.transition('green');
Tl4WAHA.transition('yellow');
Tl4WAHA.transition('red');
}
}
const Tl4AT = sm`red 'foo' => green => yellow => red; [red yellow green] ~> off -> red;`;
Tl4AT.set_hook({ handler: () => true, kind: 'any transition' });
function TransitionCycleTLWithAnyTransitionHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4AT.transition('green');
Tl4AT.transition('yellow');
Tl4AT.transition('red');
}
}
const Tl4EX = sm`red 'foo' => green => yellow => red; [red yellow green] ~> off -> red;`;
Tl4EX.set_hook({ handler: () => true, from: 'red', kind: 'exit' });
function TransitionCycleTLWithExitHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4EX.transition('green');
Tl4EX.transition('yellow');
Tl4EX.transition('red');
}
}
const Tl4EN = sm`red 'foo' => green => yellow => red; [red yellow green] ~> off -> red;`;
Tl4EN.set_hook({ handler: () => true, to: 'red', kind: 'entry' });
function TransitionCycleTLWithEnterHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4EN.transition('green');
Tl4EN.transition('yellow');
Tl4EN.transition('red');
}
}
const Tl4ST = sm`red 'foo' -> green -> yellow -> red; [red yellow green] ~> off -> red;`;
Tl4ST.set_hook({ handler: () => true, to: 'red', kind: 'standard transition' });
function TransitionCycleTLWithSTHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4ST.transition('green');
Tl4ST.transition('yellow');
Tl4ST.transition('red');
}
}
const Tl4MT = sm`red 'foo' => green => yellow => red; [red yellow green] ~> off -> red;`;
Tl4MT.set_hook({ handler: () => true, to: 'red', kind: 'main transition' });
function TransitionCycleTLWithMTHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4MT.transition('green');
Tl4MT.transition('yellow');
Tl4MT.transition('red');
}
}
const Tl4FT = sm`red 'foo' ~> green ~> yellow ~> red; [red yellow green] ~> off -> red;`;
Tl4FT.set_hook({ handler: () => true, to: 'red', kind: 'forced transition' });
function TransitionCycleTLWithFTHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4FT.transition('green');
Tl4FT.transition('yellow');
Tl4FT.transition('red');
}
}
const Tl4WA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
function ActionCycleTL100Times() {
for (let i=0; i<100; ++i) {
Tl4WA.action('next'); // to green
Tl4WA.action('next'); // to yellow
Tl4WA.action('next'); // to red
}
}
const Tl4WAWH = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
Tl4WAWH.set_hook({ from: 'red', to: 'green', handler: () => true, kind: 'hook' });
function ActionCycleTLWithHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4WAWH.action('next'); // to green
Tl4WAWH.action('next'); // to yellow
Tl4WAWH.action('next'); // to red
}
}
const Tl4WAWHA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
Tl4WAWHA.set_hook({ from: 'red', to: 'green', name: 'next', handler: () => true, kind: 'named' });
function ActionCycleTLWithNamedHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4WAWHA.action('next'); // to green
Tl4WAWHA.action('next'); // to yellow
Tl4WAWHA.action('next'); // to red
}
}
const Tl4AA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
Tl4AA.set_hook({ handler: () => true, kind: 'any action' });
function AnyActionCycleTLWithNamedHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4AA.action('next'); // to green
Tl4AA.action('next'); // to yellow
Tl4AA.action('next'); // to red
}
}
const Tl4TAA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
Tl4TAA.set_hook({ handler: () => true, kind: 'any transition' });
function ActionCycleTLWithAnyTransitionHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4TAA.action('next'); // to green
Tl4TAA.action('next'); // to yellow
Tl4TAA.action('next'); // to red
}
}
const Tl4EXA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
Tl4EXA.set_hook({ handler: () => true, from: 'red', kind: 'exit' });
function ActionCycleTLWithExitHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4EXA.action('next'); // to green
Tl4EXA.action('next'); // to yellow
Tl4EXA.action('next'); // to red
}
}
const Tl4ENA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
Tl4ENA.set_hook({ handler: () => true, to: 'red', kind: 'entry' });
function ActionCycleTLWithEnterHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4ENA.action('next'); // to green
Tl4ENA.action('next'); // to yellow
Tl4ENA.action('next'); // to red
}
}
const Tl4STA = sm`red -> green -> yellow -> red; [red yellow green] ~> off -> red;`;
Tl4STA.set_hook({ handler: () => true, kind: 'standard transition' });
function ActionCycleTLWithSTHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4STA.action('next'); // to green
Tl4STA.action('next'); // to yellow
Tl4STA.action('next'); // to red
}
}
const Tl4MTA = sm`red => green => yellow => red; [red yellow green] ~> off -> red;`;
Tl4MTA.set_hook({ handler: () => true, kind: 'main transition' });
function ActionCycleTLWithMTHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4MTA.action('next'); // to green
Tl4MTA.action('next'); // to yellow
Tl4MTA.action('next'); // to red
}
}
const Tl4FTA = sm`red ~> green ~> yellow ~> red; [red yellow green] ~> off -> red;`;
Tl4FTA.set_hook({ handler: () => true, kind: 'forced transition' });
function ActionCycleTLWithFTHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4FTA.action('next'); // to green
Tl4FTA.action('next'); // to yellow
Tl4FTA.action('next'); // to red
}
}
const Tl4GA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
Tl4GA.set_hook({ handler: () => true, kind: 'global action' });
function GlobalActionCycleTLWithNamedHooks100Times() {
for (let i=0; i<100; ++i) {
Tl4GA.action('next'); // to green
Tl4GA.action('next'); // to yellow
Tl4GA.action('next'); // to red
}
}
const Tl4KS = sm`red 'next' => green 'next' -> yellow 'next' ~> red; [red yellow green] ~> off -> red;`;
Tl4KS.set_hook({ from: 'red', to: 'green', handler: () => true, kind: 'hook' });
Tl4KS.set_hook({ from: 'red', to: 'green', name: 'next', handler: () => true, kind: 'named' });
Tl4KS.set_hook({ from: 'red', to: 'green', name: 'unused', handler: () => true, kind: 'named' });
Tl4KS.set_hook({ handler: () => true, kind: 'any transition' });
Tl4KS.set_hook({ handler: () => true, from: 'red', kind: 'exit' });
Tl4KS.set_hook({ handler: () => true, kind: 'any action' });
Tl4KS.set_hook({ handler: () => true, kind: 'any transition' });
Tl4KS.set_hook({ handler: () => true, kind: 'standard transition' });
Tl4KS.set_hook({ handler: () => true, kind: 'main transition' });
Tl4KS.set_hook({ handler: () => true, kind: 'forced transition' });
Tl4KS.set_hook({ handler: () => true, kind: 'global action' });
Tl4KS.set_hook({ handler: () => true, to: 'red', kind: 'entry' });
Tl4KS.set_hook({ handler: () => true, to: 'red', kind: 'standard transition' });
Tl4KS.set_hook({ handler: () => true, to: 'red', kind: 'main transition' });
Tl4KS.set_hook({ handler: () => true, to: 'red', kind: 'forced transition' });
function KitchenSink100Times() {
for (let i=0; i<100; ++i) {
Tl4GA.transition('green');
Tl4GA.action('next'); // to yellow
Tl4GA.force_transition('red');
}
}
function CompileTrivialABStringUsingSm() {
const ab = sm`a -> b;`;
if (ab === undefined) { throw 'not defined!'; } // prevent removal through shaking
}
function CompileTrivialABStringUsingFrom() {
const ab = jssm.from('a -> b;');
if (ab === undefined) { throw 'not defined!'; } // prevent removal through shaking
}
b.suite('General performance suite',
b.add('Blind cycle a traffic light 100 times by transition', TransitionCycleTL100Times ),
b.add('Blind cycle a traffic light 100 times by action', ActionCycleTL100Times ),
b.add('Blind cycle a basic-hooked traffic light 100 times by transition', TransitionCycleTLWithHooks100Times ),
b.add('Blind cycle a named-hooked traffic light 100 times by transition', TransitionCycleTLWithNamedHooks100Times ),
b.add('Blind cycle an any-transition traffic light 100 times by transition', TransitionCycleTLWithAnyTransitionHooks100Times ),
b.add('Blind cycle an exit hooked traffic light 100 times by transition', TransitionCycleTLWithExitHooks100Times ),
b.add('Blind cycle an enter hooked traffic light 100 times by transition', TransitionCycleTLWithEnterHooks100Times ),
b.add('Blind cycle a standard-transition hooked light by transition', TransitionCycleTLWithSTHooks100Times ),
b.add('Blind cycle a main-transition hooked light by transition', TransitionCycleTLWithMTHooks100Times ),
b.add('Blind cycle a force-transition hooked light by transition', TransitionCycleTLWithFTHooks100Times ),
b.add('Blind cycle a traffic light 100 times by action', ActionCycleTL100Times ),
b.add('Blind cycle a basic-hooked traffic light 100 times by action', ActionCycleTLWithHooks100Times ),
b.add('Blind cycle a named-hooked traffic light 100 times by action', ActionCycleTLWithNamedHooks100Times ),
b.add('Blind cycle an any-action traffic light 100 times by action', AnyActionCycleTLWithNamedHooks100Times ),
b.add('Blind cycle a global-action traffic light 100 times by action', GlobalActionCycleTLWithNamedHooks100Times ),
b.add('Blind cycle an exit hooked traffic light 100 times by action', ActionCycleTLWithExitHooks100Times ),
b.add('Blind cycle an enter hooked traffic light 100 times by action', ActionCycleTLWithEnterHooks100Times ),
b.add('Blind cycle a standard transition tl 100 times by action', ActionCycleTLWithSTHooks100Times ),
b.add('Blind cycle a main transition tl 100 times by action', ActionCycleTLWithMTHooks100Times ),
b.add('Blind cycle a forced transition tl 100 times by action', ActionCycleTLWithFTHooks100Times ),
b.add('Kitchen Sink 100 times', KitchenSink100Times ),
b.add('Compile `a -> b;` using sm', CompileTrivialABStringUsingSm ),
b.add('Compile `a -> b;` using .from', CompileTrivialABStringUsingFrom ),
b.cycle(),
b.complete(),
b.save({ file: 'general', version: '1.2.0' }),
b.save({ file: 'general', format: 'chart.html' }),
);