@shopgate/pwa-benchmark 7.30.0-alpha.10 → 7.30.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +30 -27
- package/keyFigure.js +16 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import "core-js/modules/es.array.reduce.js";
|
|
2
|
+
/* eslint-disable no-console, class-methods-use-this, eslint-comments/disable-enable-pair */
|
|
2
3
|
import KeyFigure, { KEY_FIGURE_MODE_ADD, KEY_FIGURE_METHOD_TIME, KEY_FIGURE_METHOD_COUNT, KEY_FIGURE_METHOD_OBSERVER } from "./keyFigure";
|
|
3
4
|
const HEADLINE_STYLE = 'font-size: 24px; margin-top: 32px; margin-bottom: 12px;';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Benchmark controller.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
let BenchmarkController = /*#__PURE__*/function () {
|
|
9
10
|
/**
|
|
10
11
|
* Init
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
function BenchmarkController() {
|
|
13
14
|
/**
|
|
14
15
|
* Sorts measured actions descending.
|
|
15
16
|
* @param {Array} actions Measured actions.
|
|
@@ -56,7 +57,8 @@ class BenchmarkController {
|
|
|
56
57
|
/**
|
|
57
58
|
* Startsup the controller
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
+
var _proto = BenchmarkController.prototype;
|
|
61
|
+
_proto.startup = function startup() {
|
|
60
62
|
// Redux key figures.
|
|
61
63
|
this.addKeyFigure('ActionCount', new KeyFigure(KEY_FIGURE_MODE_ADD, KEY_FIGURE_METHOD_COUNT));
|
|
62
64
|
this.addKeyFigure('ActionTime', new KeyFigure(KEY_FIGURE_MODE_ADD, KEY_FIGURE_METHOD_TIME));
|
|
@@ -71,8 +73,8 @@ class BenchmarkController {
|
|
|
71
73
|
* Adds a key figure.
|
|
72
74
|
* @param {string} name Name
|
|
73
75
|
* @param {KeyFigure} keyFigure KeyFigure
|
|
74
|
-
|
|
75
|
-
addKeyFigure(name, keyFigure) {
|
|
76
|
+
*/;
|
|
77
|
+
_proto.addKeyFigure = function addKeyFigure(name, keyFigure) {
|
|
76
78
|
this.keyFigures[name] = keyFigure;
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -81,24 +83,24 @@ class BenchmarkController {
|
|
|
81
83
|
* @param {string} name Name
|
|
82
84
|
* @param {KeyFigure} keyfigure KeyFigure
|
|
83
85
|
* @returns {Object}
|
|
84
|
-
|
|
85
|
-
getKeyFigure(name) {
|
|
86
|
+
*/;
|
|
87
|
+
_proto.getKeyFigure = function getKeyFigure(name) {
|
|
86
88
|
return this.keyFigures[name];
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
/**
|
|
90
92
|
* Benchmark debug log;
|
|
91
|
-
|
|
92
|
-
debug() {
|
|
93
|
+
*/;
|
|
94
|
+
_proto.debug = function debug() {
|
|
93
95
|
console.log('=========================');
|
|
94
96
|
console.log('Benchmark Debug Log');
|
|
95
97
|
console.log('=========================');
|
|
96
98
|
console.log(this.keyFigures);
|
|
97
|
-
}
|
|
99
|
+
};
|
|
98
100
|
/**
|
|
99
101
|
* Prints most called actions.
|
|
100
102
|
*/
|
|
101
|
-
printMostCalledActions() {
|
|
103
|
+
_proto.printMostCalledActions = function printMostCalledActions() {
|
|
102
104
|
// Most called actions.
|
|
103
105
|
const {
|
|
104
106
|
measure
|
|
@@ -115,8 +117,8 @@ class BenchmarkController {
|
|
|
115
117
|
/**
|
|
116
118
|
* Prints the highest execution time per action on average.
|
|
117
119
|
* @param {string} type "inclusive" or "exclusive"
|
|
118
|
-
|
|
119
|
-
printHighestAverageAction(type = 'inclusive') {
|
|
120
|
+
*/;
|
|
121
|
+
_proto.printHighestAverageAction = function printHighestAverageAction(type = 'inclusive') {
|
|
120
122
|
// Highest average execution time
|
|
121
123
|
const {
|
|
122
124
|
measure
|
|
@@ -135,8 +137,8 @@ class BenchmarkController {
|
|
|
135
137
|
|
|
136
138
|
/**
|
|
137
139
|
* Prints most rendering actions.
|
|
138
|
-
|
|
139
|
-
printsActionsWithMostRenders() {
|
|
140
|
+
*/;
|
|
141
|
+
_proto.printsActionsWithMostRenders = function printsActionsWithMostRenders() {
|
|
140
142
|
const measure = this.getKeyFigure('ActionEvents').measure.inclusive;
|
|
141
143
|
const actions = Object.keys(measure).map(action => Object.keys(measure[action]).reduce((acc, current) => ({
|
|
142
144
|
action,
|
|
@@ -155,11 +157,11 @@ class BenchmarkController {
|
|
|
155
157
|
SumRenderTime: action.renderTime,
|
|
156
158
|
AvgRenderTime: action.render > 0 ? action.renderTime / action.render : 0
|
|
157
159
|
})).reverse().slice(0, 10), ['Action', 'Renders', 'SumRenderTime', 'AvgRenderTime']);
|
|
158
|
-
}
|
|
160
|
+
};
|
|
159
161
|
/**
|
|
160
162
|
* Prints the most rendering components.
|
|
161
163
|
*/
|
|
162
|
-
printsMostRenderedComponents() {
|
|
164
|
+
_proto.printsMostRenderedComponents = function printsMostRenderedComponents() {
|
|
163
165
|
const measure = this.getKeyFigure('GlobalEvents').measure.inclusive;
|
|
164
166
|
const result = this.getTotals(measure);
|
|
165
167
|
const sortedAction = this.sortMeasure(result, a => a.render, b => b.render);
|
|
@@ -174,8 +176,8 @@ class BenchmarkController {
|
|
|
174
176
|
|
|
175
177
|
/**
|
|
176
178
|
* Prints summary.
|
|
177
|
-
|
|
178
|
-
printTotals() {
|
|
179
|
+
*/;
|
|
180
|
+
_proto.printTotals = function printTotals() {
|
|
179
181
|
const measure = this.getKeyFigure('GlobalEvents').measure.inclusive;
|
|
180
182
|
const result = this.getTotals(measure);
|
|
181
183
|
const sumRenders = result.reduce((current, acc) => current + acc.render, 0);
|
|
@@ -187,8 +189,8 @@ class BenchmarkController {
|
|
|
187
189
|
|
|
188
190
|
/**
|
|
189
191
|
* Pretty prints result.
|
|
190
|
-
|
|
191
|
-
print() {
|
|
192
|
+
*/;
|
|
193
|
+
_proto.print = function print() {
|
|
192
194
|
const globalEvents = this.getKeyFigure('GlobalEvents');
|
|
193
195
|
if (globalEvents.started) {
|
|
194
196
|
this.getKeyFigure('GlobalEvents').stopMeasure('global');
|
|
@@ -203,19 +205,20 @@ class BenchmarkController {
|
|
|
203
205
|
|
|
204
206
|
/**
|
|
205
207
|
* Starts benchmarking all key figures.
|
|
206
|
-
|
|
207
|
-
startAll() {
|
|
208
|
+
*/;
|
|
209
|
+
_proto.startAll = function startAll() {
|
|
208
210
|
Object.keys(this.keyFigures).forEach(keyFigure => this.keyFigures[keyFigure].setStarted(true));
|
|
209
211
|
this.getKeyFigure('GlobalEvents').startMeasure('global');
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
/**
|
|
213
215
|
* Stops benchmarking all key figures.
|
|
214
|
-
|
|
215
|
-
stopAll() {
|
|
216
|
+
*/;
|
|
217
|
+
_proto.stopAll = function stopAll() {
|
|
216
218
|
this.getKeyFigure('GlobalEvents').stopMeasure('global');
|
|
217
219
|
Object.keys(this.keyFigures).forEach(keyFigure => this.keyFigures[keyFigure].setStarted(false));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
+
};
|
|
221
|
+
return BenchmarkController;
|
|
222
|
+
}();
|
|
220
223
|
window.benchmark = new BenchmarkController();
|
|
221
224
|
export default window.benchmark;
|
package/keyFigure.js
CHANGED
|
@@ -11,13 +11,13 @@ export const KEY_FIGURE_METHOD_OBSERVER = 'observer';
|
|
|
11
11
|
/**
|
|
12
12
|
* Class
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
let KeyFigure = /*#__PURE__*/function () {
|
|
15
15
|
/**
|
|
16
16
|
* Initializes the keyfigure and set it as started.
|
|
17
17
|
* @param {string} mode Append mode.
|
|
18
18
|
* @param {string} method Method.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
function KeyFigure(mode, method) {
|
|
21
21
|
this.mode = mode;
|
|
22
22
|
this.method = method;
|
|
23
23
|
this.setStarted(true);
|
|
@@ -27,7 +27,8 @@ export default class KeyFigure {
|
|
|
27
27
|
* Toggles the status of the benchmark and also clears the result.
|
|
28
28
|
* @param {boolean} started Whether benchmark is running or not.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
var _proto = KeyFigure.prototype;
|
|
31
|
+
_proto.setStarted = function setStarted(started) {
|
|
31
32
|
if (started) {
|
|
32
33
|
this.measure = {
|
|
33
34
|
exclusiveTimers: [],
|
|
@@ -43,8 +44,8 @@ export default class KeyFigure {
|
|
|
43
44
|
/**
|
|
44
45
|
* Starts measuring.
|
|
45
46
|
* @param {string} key Unique identifier for action.
|
|
46
|
-
|
|
47
|
-
startMeasure(key) {
|
|
47
|
+
*/;
|
|
48
|
+
_proto.startMeasure = function startMeasure(key) {
|
|
48
49
|
if (!this.started) return;
|
|
49
50
|
|
|
50
51
|
// Prepare storage for key if not existing yet.
|
|
@@ -67,7 +68,10 @@ export default class KeyFigure {
|
|
|
67
68
|
if (this.method === KEY_FIGURE_METHOD_OBSERVER) {
|
|
68
69
|
// Create observer and start observing.
|
|
69
70
|
const observer = {
|
|
70
|
-
instance: new PerformanceObserver(event =>
|
|
71
|
+
instance: new PerformanceObserver(event => {
|
|
72
|
+
var _observer$stored;
|
|
73
|
+
return (_observer$stored = observer.stored).push.apply(_observer$stored, event.getEntries());
|
|
74
|
+
}),
|
|
71
75
|
events: [],
|
|
72
76
|
stored: []
|
|
73
77
|
};
|
|
@@ -82,8 +86,8 @@ export default class KeyFigure {
|
|
|
82
86
|
/**
|
|
83
87
|
* Stops measuring.
|
|
84
88
|
* @param {string} key Unique key.
|
|
85
|
-
|
|
86
|
-
stopMeasure(key) {
|
|
89
|
+
*/;
|
|
90
|
+
_proto.stopMeasure = function stopMeasure(key) {
|
|
87
91
|
if (!this.started) return;
|
|
88
92
|
|
|
89
93
|
// For counting mode just increment the call count.
|
|
@@ -196,5 +200,7 @@ export default class KeyFigure {
|
|
|
196
200
|
this.measure.inclusive[key] += currentMeasure.inclusive;
|
|
197
201
|
this.measure.exclusive[key] += currentMeasure.exclusive;
|
|
198
202
|
}
|
|
199
|
-
}
|
|
200
|
-
|
|
203
|
+
};
|
|
204
|
+
return KeyFigure;
|
|
205
|
+
}();
|
|
206
|
+
export { KeyFigure as default };
|