forked from LIGHTASCENSIONS/vercel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.js
56 lines (48 loc) · 1.45 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
46
47
48
49
50
51
52
53
54
55
56
const { join } = require('path');
const { tmpdir } = require('os');
const { mkdirSync, writeFileSync } = require('fs');
function getRandomId() {
return Math.random()
.toString()
.slice(2);
}
function getRandomInt(min, max) {
const diff = max - min;
return Math.floor(Math.random() * diff) + min;
}
function getRandomText(wordCount) {
return Array.from({ length: wordCount })
.map(getRandomId)
.join(' ');
}
function getRandomFileData() {
const wordCount = getRandomInt(1000, 2000);
return getRandomText(wordCount);
}
function createRandomFile(dir) {
const fileName = getRandomId() + '.txt';
const data = getRandomFileData();
writeFileSync(join(dir, fileName), data, 'utf8');
}
function createRandomProject(dir, fileCount) {
const nowJson = JSON.stringify(
{ version: 2, public: true, name: 'test' },
null,
' '
);
writeFileSync(join(dir, 'now.json'), nowJson, 'utf8');
const publicDir = join(dir, 'public');
mkdirSync(publicDir);
Array.from({ length: fileCount }).forEach(() => createRandomFile(publicDir));
}
function main(fileCount = 1000) {
const randomTmpId = getRandomId();
const dir = join(tmpdir(), 'now-benchmark' + randomTmpId);
console.log(`Creating ${dir} with ${fileCount} random files...`);
mkdirSync(dir);
createRandomProject(dir, Number(fileCount));
console.log(`Done. Run the following:`);
console.log(`cd ${dir}`);
console.log('time vercel --no-clipboard');
}
main(process.argv[2]);