forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimings.js
More file actions
46 lines (38 loc) · 1.27 KB
/
timings.js
File metadata and controls
46 lines (38 loc) · 1.27 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import { zip } from "lodash";
export function getAsyncTimes(name: string): number[] {
return zip(
window.performance.getEntriesByName(`${name}_start`),
window.performance.getEntriesByName(`${name}_end`)
).map(([start, end]) => +(end.startTime - start.startTime).toPrecision(2));
}
function getTimes(name) {
return window.performance
.getEntriesByName(name)
.map(time => +time.duration.toPrecision(2));
}
function getStats(times) {
if (times.length == 0) {
return { times: [], avg: null, median: null };
}
const avg = times.reduce((sum, time) => time + sum, 0) / times.length;
const sortedtimings = [...times].sort((a, b) => a - b);
const median = sortedtimings[times.length / 2];
return {
times,
avg: +avg.toPrecision(2),
median: +median.toPrecision(2)
};
}
export function steppingTimings() {
const commandTimings = getAsyncTimes("COMMAND");
const pausedTimings = getTimes("PAUSED");
return {
commands: getStats(commandTimings),
paused: getStats(pausedTimings)
};
}
// console.log("..", asyncTimes("COMMAND"));