-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst.js
32 lines (26 loc) · 855 Bytes
/
first.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
const crypto = require("crypto");
const hash = (input) =>
new Promise((resolve) => {
const start = Date.now();
for (let i = 0; i < 500000; i++) {
input = crypto.createHash("sha256").update(input).digest("hex");
}
console.log(`Hashing done in ${Date.now() - start} ms`);
resolve(input);
});
const main = async () => {
const start = Date.now();
const hashes = await Promise.all([
hash("Hash this text 500k times!"),
hash("Hash this text 500k times!"),
hash("Hash this text 500k times!"),
hash("Hash this text 500k times!"),
hash("Hash this text 500k times!"),
hash("Hash this text 500k times!"),
hash("Hash this text 500k times!"),
hash("Hash this text 500k times!"),
]);
console.log(hashes);
console.log(`Main done in ${Date.now() - start} ms`);
};
main().catch(console.error);