-
Notifications
You must be signed in to change notification settings - Fork 6
/
counters.js
59 lines (47 loc) · 1.17 KB
/
counters.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
class FPSCounter {
constructor() {
this.bufferSize = 12;
this.fps = new Array(this.bufferSize).fill(0);
this.ms = new Array(this.bufferSize).fill(0);
this.then = Date.now();
this.frames = 0;
}
inc() {
this.frames++;
}
update() {
const now = Date.now();
const lapsed = now - this.then;
const fps = this.frames / lapsed * 1000;
const ms = lapsed / this.frames;
if (this.fps.length > this.bufferSize) {
this.fps.shift();
this.ms.shift();
}
this.fps.push(fps);
this.ms.push(ms);
this.frames = 0;
this.currentFps = fps;
this.currentMs = ms;
this.then = now;
}
}
class MemCounter {
constructor() {
this.bufferSize = 12;
this.data = new Array(this.bufferSize).fill(0);
this.current;
}
update() {
const rss = process.memoryUsage().rss / 1024 / 1024;
this.current = rss;
if (this.data.length > this.bufferSize) {
this.data.shift();
}
this.data.push(rss);
}
}
module.exports = {
FPSCounter,
MemCounter
};