1
1
import fs from 'fs' ;
2
- import path , { dirname } from 'path' ;
2
+ import path , { dirname , join } from 'path' ;
3
3
import { fileURLToPath } from 'url' ;
4
4
import Table from 'cli-table' ;
5
+ import glob from 'fast-glob' ;
5
6
import Benchmark from 'benchmark' ;
6
7
import { parse } from '../packages/react-docgen/dist/main.js' ;
7
- import { parse as parse4 } from 'react-docgen4' ;
8
8
import { parse as parse5 } from 'react-docgen5' ;
9
9
import { parse as parse6old } from 'react-docgen6pre' ;
10
10
11
11
console . log ( `Node: ${ process . version } ` ) ;
12
12
13
13
const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
14
14
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' ] ;
16
16
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
+ ] ;
18
28
19
29
const table = new Table ( {
20
30
head,
@@ -31,29 +41,45 @@ if (!global.gc) {
31
41
process . exit ( ) ;
32
42
}
33
43
34
- files . forEach ( file => {
35
- const code = fs . readFileSync ( path . join ( __dirname , file ) , 'utf-8' ) ;
36
- const suite = new Benchmark . Suite ( file . replace ( / \. \/ _ _ f i x t u r e s _ _ \/ / , '' ) ) ;
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 { }
48
67
} ) ;
68
+
49
69
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
+ }
51
73
} ) ;
52
74
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
+ }
54
78
} ) ;
55
79
suite . add ( 'current' , ( ) => {
56
- parse ( code , newOptions ) ;
80
+ for ( const { code, newOptions } of preparedSuites ) {
81
+ parse ( code , newOptions ) ;
82
+ }
57
83
} ) ;
58
84
const result = [ suite . name ] ;
59
85
@@ -76,11 +102,12 @@ files.forEach(file => {
76
102
) ;
77
103
} ) ;
78
104
79
- process . stdout . write ( `Running benchmark for ${ suite . name } ... ` ) ;
105
+ process . stdout . write ( `Done\nRunning benchmark for ${ suite . name } ... ` ) ;
80
106
global . gc ( ) ;
81
107
suite . run ( { async : false } ) ;
82
108
global . gc ( ) ; // gc is disabled so ensure we run it
83
109
table . push ( result ) ;
84
110
} ) ;
111
+
85
112
global . gc ( ) ; // gc is disabled so ensure we run it
86
113
console . log ( table . toString ( ) ) ;
0 commit comments