-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathperformance-check.js
51 lines (41 loc) · 1.12 KB
/
performance-check.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
'use strict';
/*
* Fill the display with each character and determine how often the display
* can be filled per second. At the same time, determine how often
* setInterval(..., 1) times out per second.
*/
const Lcd = require('../lcd');
const lcd = new Lcd({rs: 23, e: 24, data: [17, 18, 22, 27], cols: 20, rows: 4});
let charCode = 0;
let timeouts = 0;
let time;
let iv;
const fillDisplay = _ => {
lcd.print(new Array(20 * 4 + 1).join(String.fromCharCode(charCode)));
charCode += 1;
};
const printResults = _ => {
let seconds;
let displayFillsPerSec;
let timeoutsPerSec;
time = process.hrtime(time);
seconds = time[0] + time[1] / 1E9;
displayFillsPerSec = Math.floor(256 / seconds);
console.log(displayFillsPerSec + ' display fills per second');
timeoutsPerSec = Math.floor(timeouts / seconds);
console.log(timeoutsPerSec + ' timeouts per second');
};
lcd.on('ready',_ => {
time = process.hrtime();
iv = setInterval(_ => timeouts += 1, 1);
fillDisplay();
});
lcd.on('printed', _ => {
if (charCode < 256) {
fillDisplay();
} else {
printResults();
clearInterval(iv);
lcd.close();
}
});