-
Notifications
You must be signed in to change notification settings - Fork 20
/
benchmark.js
45 lines (36 loc) · 1.2 KB
/
benchmark.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
/* eslint-disable no-console,no-await-in-loop */
const fs = require('fs');
const { promisify } = require('util');
const proxymise = require('..');
const mkdir = promisify(fs.mkdir);
const writeFile = promisify(fs.writeFile);
const readFile = promisify(fs.readFile);
const unlink = promisify(fs.unlink);
const rmdir = promisify(fs.rmdir);
async function benchmark() {
const dir = 'benchmark';
const count = 10000;
await mkdir(dir);
console.log(`${count} iterations`);
console.time('with proxymise');
for (let i = 0; i < count; i += 1) {
const path = `${dir}/${i}.txt`;
await proxymise(writeFile)(path, i);
const value = await proxymise(readFile)(path).toString();
if (value !== i.toString()) throw new Error(value);
await proxymise(unlink)(path);
}
console.timeEnd('with proxymise');
console.time('without proxymise');
for (let i = 0; i < count; i += 1) {
const path = `${dir}/${i}.txt`;
await writeFile(path, i);
const buffer = await readFile(path);
const value = buffer.toString();
if (value !== i.toString()) throw new Error(value);
await unlink(path);
}
console.timeEnd('without proxymise');
await rmdir(dir);
}
benchmark().catch(console.error);