-
Notifications
You must be signed in to change notification settings - Fork 21
/
benchmark.js
90 lines (47 loc) · 2.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
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 TransitionCycleFourPointTrafficLight500Times() {
for (let i=0; i<500; ++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 TransitionCycleFourPointTrafficLightWithHooks500Times() {
for (let i=0; i<500; ++i) {
Tl4WH.transition('green');
Tl4WH.transition('yellow');
Tl4WH.transition('red');
}
}
const Tl4WA = sm`red 'next' => green 'next' => yellow 'next' => red; [red yellow green] ~> off -> red;`;
function ActionCycleFourPointTrafficLight500Times() {
for (let i=0; i<500; ++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 ActionCycleFourPointTrafficLightWithHooks500Times() {
for (let i=0; i<500; ++i) {
Tl4WAWH.action('next'); // to green
Tl4WAWH.action('next'); // to yellow
Tl4WAWH.action('next'); // to red
}
}
b.suite('General performance suite',
b.add('Blind cycle a traffic light 500 times by transition', TransitionCycleFourPointTrafficLight500Times ),
b.add('Blind cycle a hooked traffic light 500 times by transition', TransitionCycleFourPointTrafficLightWithHooks500Times ),
b.add('Blind cycle a traffic light 500 times by action', ActionCycleFourPointTrafficLight500Times ),
b.add('Blind cycle a hooked traffic light 500 times by action', ActionCycleFourPointTrafficLightWithHooks500Times ),
b.cycle(),
b.complete(),
b.save({ file: 'general', version: '1.1.0' }),
b.save({ file: 'general', format: 'chart.html' }),
);