Created
March 18, 2018 07:59
-
-
Save muhsin-k/00dbacefa42d520ce715dc898d04bc5b to your computer and use it in GitHub Desktop.
Event Loop Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(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); | |
}); | |
doHash(); | |
doHash(); | |
doHash(); | |
doHash(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment