-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.bench.ts
More file actions
76 lines (59 loc) · 2.4 KB
/
index.bench.ts
File metadata and controls
76 lines (59 loc) · 2.4 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { Repository as SimpleGitRepository } from '@napi-rs/simple-git';
import { Repository as NodeGitRepository, Revparse as NodeGitRevparse } from 'nodegit';
import { bench, describe } from 'vitest';
import { openRepository } from '../index';
import { createBenchmark, exec } from './util';
const dirname = path.dirname(fileURLToPath(import.meta.url));
const gitDir = path.resolve(dirname, '..');
const benchmark = createBenchmark(gitDir);
describe('open', () => {
bench('es-git', async () => {
await openRepository(gitDir);
});
bench('nodegit', async () => {
await NodeGitRepository.open(gitDir);
});
bench('@napi-rs/simple-git', () => {
new SimpleGitRepository(gitDir);
});
});
describe('rev-parse', () => {
benchmark.esGit('es-git', repo => repo.revparse('HEAD'));
benchmark.nodegit('nodegit', repo => NodeGitRevparse.single(repo, 'HEAD'));
benchmark.simpleGit('@napi-rs/simple-git', repo => repo.head().resolve());
benchmark.childProcess('child_process', () => exec('git rev-parse HEAD', gitDir));
});
describe('revwalk', () => {
benchmark.esGit('es-git', repo => {
const revwalk = repo.revwalk().pushRange('b597cf0b..d47af3b0');
const oids = [];
let oid = revwalk.next();
while (oid != null) {
oids.push(oid);
oid = revwalk.next();
}
console.assert(oids.length === 103);
});
benchmark.nodegit('nodegit', async repo => {
const revwalk = repo.createRevWalk();
revwalk.pushRange('b597cf0b..d47af3b0');
const oids = await revwalk.fastWalk(200);
console.assert(oids.length === 103);
});
benchmark.simpleGit('@napi-rs/simple-git', repo => {
const revwalk = repo.revWalk();
const oids = [...revwalk.pushRange('b597cf0b..d47af3b0')];
console.assert(oids.length === 103);
});
benchmark.childProcess('child_process', async () => {
await exec('git log b597cf0b..d47af3b0', gitDir);
});
});
describe('get commit', () => {
benchmark.esGit('es-git', repo => repo.getCommit('d47af3b02b36834dcde1b60afb64547460f5abc0'));
benchmark.nodegit('nodegit', repo => repo.getCommit('d47af3b02b36834dcde1b60afb64547460f5abc0'));
benchmark.simpleGit('@napi-rs/simple-git', repo => repo.findCommit('d47af3b02b36834dcde1b60afb64547460f5abc0'));
benchmark.childProcess('child_process', () => exec('git log d47af3b02b36834dcde1b60afb64547460f5abc0', gitDir));
});