-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (47 loc) · 1.42 KB
/
index.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
const desktopScreenshot = require('desktop-screenshot');
const screenshotDesktop = require('screenshot-desktop');
const { capturePrimaryMonitor } = require('windows-ss');
const fs = require('fs');
const { performance } = require('perf_hooks');
if (!process.env.RUNS) process.env.RUNS = 1000;
if (!process.env.FORMAT) process.env.FORMAT = 'bmp';
fs.mkdirSync('./out', { recursive: true });
const functions = [
windowsSSFile,
windowsSSBuffer,
screenshotDesktopFile,
screenshotDesktopBuffer,
desktopScreenshotFile,
];
(async () => {
for (const func of functions) {
const start = performance.now();
for (let i = 0, l = process.env.RUNS; i < l; ++i) {
await func();
}
console.log(`${func.name}: ${performance.now() - start}ms`);
}
})();
async function windowsSSFile() {
await capturePrimaryMonitor({ save: `./out/windows-ss.${process.env.FORMAT}` });
}
async function windowsSSBuffer() {
await capturePrimaryMonitor({ format: process.env.FORMAT });
}
async function screenshotDesktopFile() {
await screenshotDesktop({ filename: `./out/screenshot-desktop.${process.env.FORMAT}`, });
}
async function screenshotDesktopBuffer() {
await screenshotDesktop({ format: process.env.FORMAT });
}
async function desktopScreenshotFile() {
await new Promise((resolve, reject) => {
desktopScreenshot(`./out/desktop-screenshot.${process.env.FORMAT}`, (err) => {
if (err) {
reject(err);
return;
}
resolve();
});
});
}