-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathmultitask.js
More file actions
39 lines (31 loc) · 806 Bytes
/
multitask.js
File metadata and controls
39 lines (31 loc) · 806 Bytes
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
// Expanding the Thread Pool to take 5 threads
// process.env.UV_THREADPOOL_SIZE = 5;
const https = require('https');
const crypto = require('crypto');
const fs = require('fs');
const start = Date.now();
function doRequest() {
https.request('https://www.google.com', res => {
res.on('data', () => {
});
res.on('end', () => {
console.log("HTTP Request: ", Date.now() - start);
});
}).end();
}
function doHash() {
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => {
console.log('Hash:', Date.now() - start);
});
}
doRequest();
fs.readFile('multitask.js', 'utf8', () => {
console.log("FS: ", Date.now() - start);
});
// If we comment one of those guys, we will have 4 spaces in our thread pool
// 1) FS
// 2, 3, 4) doHash
doHash();
doHash();
doHash();
doHash();