-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperformance.mjs
59 lines (47 loc) · 1.23 KB
/
performance.mjs
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 { exec } from 'child_process'
import prettyMs from 'pretty-ms'
import { Repository } from './index.js'
const GIT_DIR = '.'
const FILE = 'src/lib.rs'
const repo = new Repository(GIT_DIR)
const startChildProcessTime = process.hrtime.bigint()
await Promise.all(
Array.from({ length: 1000 }).map(
() =>
new Promise((resolve, reject) => {
let output = ''
const cp = exec(
`git log -1 --format=%cd --date=iso ${FILE}`,
{
encoding: 'utf8',
cwd: GIT_DIR,
},
(err, stdout) => {
if (err) {
return reject(err)
}
output += stdout
}
)
cp.on('close', () => {
resolve(new Date(output))
})
})
)
)
const childProcessNs = process.hrtime.bigint() - startChildProcessTime
console.info(
'Child process took %s',
prettyMs(Number(childProcessNs) / 1000_000)
)
const startLibGit2 = process.hrtime.bigint()
await Promise.all(
Array.from({ length: 1000 }).map(() =>
repo.getFileLatestModifiedDateAsync(FILE)
)
)
const libGit2Ns = process.hrtime.bigint() - startLibGit2
console.info(
'@napi-rs/simple-git took %s',
prettyMs(Number(libGit2Ns) / 1000_000)
)