Skip to content

Commit e61c64a

Browse files
committed
update benchmark to test against react-bootstrap
1 parent d4c27d4 commit e61c64a

File tree

5 files changed

+208
-342
lines changed

5 files changed

+208
-342
lines changed

benchmark/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
suites/
12
yarn-error.log
23
.pnp.*
34
.yarn/*

benchmark/__fixtures__/CircularProgress.js

Lines changed: 0 additions & 249 deletions
This file was deleted.

benchmark/index.mjs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import fs from 'fs';
2-
import path, { dirname } from 'path';
2+
import path, { dirname, join } from 'path';
33
import { fileURLToPath } from 'url';
44
import Table from 'cli-table';
5+
import glob from 'fast-glob';
56
import Benchmark from 'benchmark';
67
import { parse } from '../packages/react-docgen/dist/main.js';
7-
import { parse as parse4 } from 'react-docgen4';
88
import { parse as parse5 } from 'react-docgen5';
99
import { parse as parse6old } from 'react-docgen6pre';
1010

1111
console.log(`Node: ${process.version}`);
1212

1313
const __dirname = dirname(fileURLToPath(import.meta.url));
1414

15-
const head = ['fixture', 'v4.1.1', 'v5.4.3', 'v6.0.0-alpha.3', 'current'];
15+
const head = ['fixture', 'v5.4.3', 'v6.0.0-alpha.3', 'current'];
1616

17-
const files = ['./__fixtures__/CircularProgress.js'];
17+
process.stdout.write(`Preparing suites ... `);
18+
19+
const suites = [
20+
{
21+
name: 'react-bootstrap',
22+
files: await glob('./suites/react-bootstrap/src/*.tsx', {
23+
absolute: false,
24+
cwd: __dirname,
25+
}),
26+
},
27+
];
1828

1929
const table = new Table({
2030
head,
@@ -31,29 +41,45 @@ if (!global.gc) {
3141
process.exit();
3242
}
3343

34-
files.forEach(file => {
35-
const code = fs.readFileSync(path.join(__dirname, file), 'utf-8');
36-
const suite = new Benchmark.Suite(file.replace(/\.\/__fixtures__\//, ''));
37-
const options = { filename: file, babelrc: false, configFile: false };
38-
const newOptions = { babelOptions: options };
39-
40-
// warmup
41-
parse(code, newOptions);
42-
parse6old(code, undefined, undefined, options);
43-
parse5(code, undefined, undefined, options);
44-
parse4(code, undefined, undefined, options);
45-
global.gc();
46-
suite.add('v4.1.1', () => {
47-
parse4(code, undefined, undefined, options);
44+
const preparedSuites = [];
45+
const suite = new Benchmark.Suite('bootstrap');
46+
47+
suites.forEach(({ name, files }) => {
48+
const suite = new Benchmark.Suite(name);
49+
files.forEach(file => {
50+
const code = fs.readFileSync(path.join(__dirname, file), 'utf-8');
51+
const options = { filename: file, babelrc: false, configFile: false };
52+
const newOptions = { babelOptions: options };
53+
54+
try {
55+
// warmup
56+
parse(code, newOptions);
57+
parse6old(code, undefined, undefined, options);
58+
parse5(code, undefined, undefined, options);
59+
global.gc();
60+
61+
preparedSuites.push({
62+
code,
63+
options,
64+
newOptions,
65+
});
66+
} catch {}
4867
});
68+
4969
suite.add('v5.4.3', () => {
50-
parse5(code, undefined, undefined, options);
70+
for (const { code, options } of preparedSuites) {
71+
parse5(code, undefined, undefined, options);
72+
}
5173
});
5274
suite.add('v6.0.0-alpha.3', () => {
53-
parse6old(code, undefined, undefined, options);
75+
for (const { code, options } of preparedSuites) {
76+
parse6old(code, undefined, undefined, options);
77+
}
5478
});
5579
suite.add('current', () => {
56-
parse(code, newOptions);
80+
for (const { code, newOptions } of preparedSuites) {
81+
parse(code, newOptions);
82+
}
5783
});
5884
const result = [suite.name];
5985

@@ -76,11 +102,12 @@ files.forEach(file => {
76102
);
77103
});
78104

79-
process.stdout.write(`Running benchmark for ${suite.name} ... `);
105+
process.stdout.write(`Done\nRunning benchmark for ${suite.name} ... `);
80106
global.gc();
81107
suite.run({ async: false });
82108
global.gc(); // gc is disabled so ensure we run it
83109
table.push(result);
84110
});
111+
85112
global.gc(); // gc is disabled so ensure we run it
86113
console.log(table.toString());

benchmark/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
"private": true,
55
"description": "Generate benchmarks for react-docgen",
66
"scripts": {
7+
"setup": "rm -rf ./suites/react-bootstrap/ && git clone --depth=1 --branch=v2.7.0 https://github.com/react-bootstrap/react-bootstrap.git ./suites/react-bootstrap/",
78
"start": "node --expose-gc ./index.mjs",
89
"debug": "node --inspect-brk --expose-gc ./index.mjs"
910
},
1011
"license": "MIT",
1112
"dependencies": {
1213
"benchmark": "2.1.4",
1314
"cli-table": "0.3.11",
15+
"fast-glob": "^3.2.12",
1416
"microtime": "3.1.1",
15-
"react-docgen4": "npm:[email protected]",
1617
"react-docgen5": "npm:[email protected]",
1718
"react-docgen6pre": "npm:react-docgen@^6.0.0-alpha"
1819
}

0 commit comments

Comments
 (0)