Skip to content

Commit d71674c

Browse files
committed
chore: Fix benchmark
1 parent 07a9acd commit d71674c

File tree

6 files changed

+2073
-214
lines changed

6 files changed

+2073
-214
lines changed

benchmark/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
yarn-error.log
2+
.pnp.*
3+
.yarn/*
4+
!.yarn/patches
5+
!.yarn/plugins
6+
!.yarn/releases
7+
!.yarn/sdks
8+
!.yarn/versions

benchmark/index.js renamed to benchmark/index.mjs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const Table = require('cli-table');
4-
const Benchmark = require('benchmark');
5-
const { parse } = require('../packages/react-docgen');
6-
const { parse: parse4 } = require('react-docgen4');
7-
const { parse: parse5 } = require('react-docgen5');
8-
const { parse: parse6old } = require('react-docgen6pre');
1+
import fs from 'fs';
2+
import path, { dirname } from 'path';
3+
import { fileURLToPath } from 'url';
4+
import Table from 'cli-table';
5+
import Benchmark from 'benchmark';
6+
import { parse } from '../packages/react-docgen/dist/main.js';
7+
import { parse as parse4 } from 'react-docgen4';
8+
import { parse as parse5 } from 'react-docgen5';
9+
import { parse as parse6old } from 'react-docgen6pre';
910

1011
console.log(`Node: ${process.version}`);
1112

12-
const head = ['fixture', 'current', 'v6.0.0-alpha.3', 'v5.4.3', 'v4.1.1'];
13+
const __dirname = dirname(fileURLToPath(import.meta.url));
1314

14-
const files = ['./fixtures/CircularProgress.js'];
15+
const head = ['fixture', 'v4.1.1', 'v5.4.3', 'v6.0.0-alpha.3', 'current'];
16+
17+
const files = ['./__fixtures__/CircularProgress.js'];
1518

1619
const table = new Table({
1720
head,
@@ -30,7 +33,7 @@ if (!global.gc) {
3033

3134
files.forEach(file => {
3235
const code = fs.readFileSync(path.join(__dirname, file), 'utf-8');
33-
const suite = new Benchmark.Suite(file.replace(/\.\/fixtures\//, ''));
36+
const suite = new Benchmark.Suite(file.replace(/\.\/__fixtures__\//, ''));
3437
const options = { filename: file, babelrc: false, configFile: false };
3538
const newOptions = { babelOptions: options };
3639

@@ -40,17 +43,17 @@ files.forEach(file => {
4043
parse5(code, undefined, undefined, options);
4144
parse4(code, undefined, undefined, options);
4245
global.gc();
43-
suite.add('current', () => {
44-
parse(code, newOptions);
45-
});
46-
suite.add('v6.0.0-alpha.3', () => {
47-
parse6old(code, undefined, undefined, options);
46+
suite.add('v4.1.1', () => {
47+
parse4(code, undefined, undefined, options);
4848
});
4949
suite.add('v5.4.3', () => {
5050
parse5(code, undefined, undefined, options);
5151
});
52-
suite.add('v4.1.1', () => {
53-
parse4(code, undefined, undefined, options);
52+
suite.add('v6.0.0-alpha.3', () => {
53+
parse6old(code, undefined, undefined, options);
54+
});
55+
suite.add('current', () => {
56+
parse(code, newOptions);
5457
});
5558
const result = [suite.name];
5659

benchmark/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"description": "Generate benchmarks for react-docgen",
66
"scripts": {
7-
"start": "node --expose-gc ./index.js",
8-
"debug": "node --inspect-brk --expose-gc ./index.js"
7+
"start": "node --expose-gc ./index.mjs",
8+
"debug": "node --inspect-brk --expose-gc ./index.mjs"
99
},
1010
"license": "MIT",
1111
"dependencies": {
@@ -14,6 +14,6 @@
1414
"microtime": "3.1.1",
1515
"react-docgen4": "npm:[email protected]",
1616
"react-docgen5": "npm:[email protected]",
17-
"react-docgen6pre": "npm:[email protected].3"
17+
"react-docgen6pre": "npm:react-docgen@^6.0.0-alpha"
1818
}
1919
}

0 commit comments

Comments
 (0)