forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
59 lines (44 loc) · 1.33 KB
/
run.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
57
58
59
import { join } from 'path'
import { ensureDir, outputFile, remove } from 'fs-extra'
import recursiveCopyNpm from 'recursive-copy'
import { recursiveCopy as recursiveCopyCustom } from 'next/dist/lib/recursive-copy'
const fixturesDir = join(__dirname, 'fixtures')
const srcDir = join(fixturesDir, 'src')
const destDir = join(fixturesDir, 'dest')
const createSrcFolder = async () => {
await ensureDir(srcDir)
const files = new Array(100)
.fill(undefined)
.map((_, i) =>
join(srcDir, `folder${i % 5}`, `folder${i + (1 % 5)}`, `file${i}`)
)
await Promise.all(files.map((file) => outputFile(file, 'hello')))
}
async function run(fn) {
async function test() {
const start = process.hrtime()
await fn(srcDir, destDir)
const timer = process.hrtime(start)
const ms = (timer[0] * 1e9 + timer[1]) / 1e6
return ms
}
const ts = []
for (let i = 0; i < 10; i++) {
const t = await test()
await remove(destDir)
ts.push(t)
}
const sum = ts.reduce((a, b) => a + b)
const nb = ts.length
const avg = sum / nb
console.log({ sum, nb, avg })
}
async function main() {
await createSrcFolder()
console.log('test recursive-copy npm module')
await run(recursiveCopyNpm)
console.log('test recursive-copy custom implementation')
await run(recursiveCopyCustom)
await remove(fixturesDir)
}
main()