@@ -13,44 +13,61 @@ function perfTest(): void {
1313 return result ;
1414 }
1515 function showResult ( ) : void {
16+ const maxLen = Math . max ( ...Object . keys ( durationRecord ) . map ( s => s . length ) ) ;
1617 for ( const key in durationRecord ) {
1718 const durations = durationRecord [ key ] ;
1819 const avg = durations . reduce ( ( a , b ) => a + b , 0 ) / durations . length ;
1920 const max = Math . max ( ...durations ) ;
2021
21- console . log ( `${ key } :\tavg=${ Number ( avg . toExponential ( 2 ) ) } ms\tmax=${ Number ( max . toExponential ( 2 ) ) } ms` ) ;
22+ console . log (
23+ `${ ( key + ":" ) . padEnd ( maxLen ) } \tavg=${ Number ( avg . toExponential ( 2 ) ) } ms\tmax=${ Number ( max . toExponential ( 2 ) ) } ms`
24+ ) ;
2225 }
2326 }
2427
2528 let errors = 0 ;
2629 let counter = 0 ;
2730 for ( const literal of PrismRegexes ) {
28- process . stdout . write ( `\r${ ++ counter } /${ PrismRegexes . length } ` ) ;
31+ counter ++ ;
32+ if ( counter === 862 ) {
33+ // this regex creates a DFA with >500k states. The DFA just doesn't fit into Node's limit of 2GB memory
34+ continue ;
35+ }
36+ process . stdout . write ( `\r${ counter } /${ PrismRegexes . length } ` ) ;
2937 if ( counter === PrismRegexes . length ) {
3038 console . log ( ) ;
3139 }
3240
3341 try {
3442 const parser = measure ( "Create parser" , ( ) => JS . Parser . fromLiteral ( literal ) ) ;
35- const { expression, maxCharacter } = measure ( "parse" , ( ) =>
36- parser . parse ( {
37- backreferences : "disable" ,
38- assertions : "disable" ,
39- } )
40- ) ;
43+ const { expression, maxCharacter } = measure ( "parse" , ( ) => parser . parse ( { backreferences : "disable" , maxNodes : 100_000 } ) ) ;
44+ measure ( "toLiteral" , ( ) => JS . toLiteral ( expression ) ) ;
45+ measure ( "toLiteral fast" , ( ) => JS . toLiteral ( expression , { fastCharacters : true } ) ) ;
46+
4147 const nfa = measure ( "Create NFA" , ( ) =>
4248 NFA . fromRegex (
4349 expression ,
4450 { maxCharacter } ,
4551 { assertions : "disable" }
4652 )
4753 ) ;
54+ measure ( "toRegex NFA" , ( ) => nfa . toRegex ( { maxNodes : 100_000 } ) ) ;
4855 const dfa = measure ( "Create DFA" , ( ) => DFA . fromFA ( nfa ) ) ;
4956 measure ( "Minimize DFA" , ( ) => dfa . minimize ( ) ) ;
57+
58+ measure ( "toRegex mDFA" , ( ) => {
59+ try {
60+ dfa . toRegex ( { maxNodes : 100_000 } )
61+ } catch ( error ) {
62+ if ( ! String ( error ) . includes ( "Too many RE AST nodes" ) ) {
63+ throw error ;
64+ }
65+ }
66+ } ) ;
5067 } catch ( error ) {
5168 errors ++ ;
5269 console . log ( `Error in ${ literal } ` ) ;
53- // throw error;
70+ throw error ;
5471 }
5572 }
5673
0 commit comments