@@ -44,19 +44,39 @@ class Report {
44
44
if ( JSON . stringify ( update . config . metadata ) !== JSON . stringify ( ref . config . metadata ) ) {
45
45
throw new Error ( 'Reports produced with non matching metadata' ) ;
46
46
}
47
- return Object . keys ( update . info . methods )
47
+
48
+ const deployments = update . info . deployments
49
+ . map ( contract => Object . assign (
50
+ contract ,
51
+ { previousVersion : ref . info . deployments . find ( ( { name } ) => name === contract . name ) } ,
52
+ ) )
53
+ . filter ( contract => contract . gasData ?. length && contract . previousVersion ?. gasData ?. length )
54
+ . flatMap ( contract => [ {
55
+ contract : contract . name ,
56
+ method : '[bytecode length]' ,
57
+ avg : variation ( contract . bytecode . length / 2 - 1 , contract . previousVersion . bytecode . length / 2 - 1 ) ,
58
+ } , {
59
+ contract : contract . name ,
60
+ method : '[construction cost]' ,
61
+ avg : variation ( ...[ contract . gasData , contract . previousVersion . gasData ] . map ( x => Math . round ( average ( ...x ) ) ) ) ,
62
+ } ] )
63
+ . sort ( ( a , b ) => `${ a . contract } :${ a . method } ` . localeCompare ( `${ b . contract } :${ b . method } ` ) ) ;
64
+
65
+ const methods = Object . keys ( update . info . methods )
48
66
. filter ( key => ref . info . methods [ key ] )
49
67
. filter ( key => update . info . methods [ key ] . numberOfCalls > 0 )
50
68
. filter ( key => update . info . methods [ key ] . numberOfCalls === ref . info . methods [ key ] . numberOfCalls )
51
69
. map ( key => ( {
52
70
contract : ref . info . methods [ key ] . contract ,
53
71
method : ref . info . methods [ key ] . fnSig ,
54
- min : variation ( ...[ update , ref ] . map ( x => ~ ~ Math . min ( ...x . info . methods [ key ] . gasData ) ) ) ,
55
- max : variation ( ...[ update , ref ] . map ( x => ~ ~ Math . max ( ...x . info . methods [ key ] . gasData ) ) ) ,
56
- avg : variation ( ...[ update , ref ] . map ( x => ~ ~ average ( ...x . info . methods [ key ] . gasData ) ) ) ,
72
+ min : variation ( ...[ update , ref ] . map ( x => Math . min ( ...x . info . methods [ key ] . gasData ) ) ) ,
73
+ max : variation ( ...[ update , ref ] . map ( x => Math . max ( ...x . info . methods [ key ] . gasData ) ) ) ,
74
+ avg : variation ( ...[ update , ref ] . map ( x => Math . round ( average ( ...x . info . methods [ key ] . gasData ) ) ) ) ,
57
75
} ) )
58
- . filter ( row => ! opts . hideEqual || ( row . min . delta && row . max . delta && row . avg . delta ) )
59
- . sort ( ( a , b ) => `${ a . contract } :${ a . method } ` < `${ b . contract } :${ b . method } ` ? - 1 : 1 ) ;
76
+ . sort ( ( a , b ) => `${ a . contract } :${ a . method } ` . localeCompare ( `${ b . contract } :${ b . method } ` ) ) ;
77
+
78
+ return [ ] . concat ( deployments , methods )
79
+ . filter ( row => ! opts . hideEqual || row . min ?. delta || row . max ?. delta || row . avg ?. delta ) ;
60
80
}
61
81
}
62
82
@@ -70,11 +90,11 @@ function plusSign (num) {
70
90
}
71
91
72
92
function formatCellShell ( cell ) {
73
- const format = chalk [ cell . delta > 0 ? 'red' : cell . delta < 0 ? 'green' : 'reset' ] ;
93
+ const format = chalk [ cell ? .delta > 0 ? 'red' : cell ? .delta < 0 ? 'green' : 'reset' ] ;
74
94
return [
75
- format ( ( isNaN ( cell . value ) ? '-' : cell . value . toString ( ) ) . padStart ( 8 ) ) ,
76
- format ( ( isNaN ( cell . delta ) ? '-' : plusSign ( cell . delta ) + cell . delta . toString ( ) ) . padStart ( 8 ) ) ,
77
- format ( ( isNaN ( cell . prcnt ) ? '-' : plusSign ( cell . prcnt ) + cell . prcnt . toFixed ( 2 ) + '%' ) . padStart ( 8 ) ) ,
95
+ format ( ( ! isFinite ( cell ? .value ) ? '-' : cell . value . toString ( ) ) . padStart ( 8 ) ) ,
96
+ format ( ( ! isFinite ( cell ? .delta ) ? '-' : plusSign ( cell . delta ) + cell . delta . toString ( ) ) . padStart ( 8 ) ) ,
97
+ format ( ( ! isFinite ( cell ? .prcnt ) ? '-' : plusSign ( cell . prcnt ) + cell . prcnt . toFixed ( 2 ) + '%' ) . padStart ( 8 ) ) ,
78
98
] ;
79
99
}
80
100
@@ -87,8 +107,8 @@ function formatCmpShell (rows) {
87
107
{ txt : 'Contract' , length : contractLength } ,
88
108
{ txt : 'Method' , length : methodLength } ,
89
109
{ txt : 'Min' , length : 30 } ,
90
- { txt : 'Avg' , length : 30 } ,
91
110
{ txt : 'Max' , length : 30 } ,
111
+ { txt : 'Avg' , length : 30 } ,
92
112
{ txt : '' , length : 0 } ,
93
113
] ;
94
114
const HEADER = COLS . map ( entry => chalk . bold ( center ( entry . txt , entry . length || 0 ) ) ) . join ( ' | ' ) . trim ( ) ;
@@ -102,8 +122,8 @@ function formatCmpShell (rows) {
102
122
chalk . grey ( entry . contract . padEnd ( contractLength ) ) ,
103
123
entry . method . padEnd ( methodLength ) ,
104
124
...formatCellShell ( entry . min ) ,
105
- ...formatCellShell ( entry . avg ) ,
106
125
...formatCellShell ( entry . max ) ,
126
+ ...formatCellShell ( entry . avg ) ,
107
127
'' ,
108
128
] . join ( ' | ' ) . trim ( ) ) ,
109
129
'' ,
@@ -132,9 +152,9 @@ function trend (value) {
132
152
133
153
function formatCellMarkdown ( cell ) {
134
154
return [
135
- ( isNaN ( cell . value ) ? '-' : cell . value . toString ( ) ) ,
136
- ( isNaN ( cell . delta ) ? '-' : plusSign ( cell . delta ) + cell . delta . toString ( ) ) ,
137
- ( isNaN ( cell . prcnt ) ? '-' : plusSign ( cell . prcnt ) + cell . prcnt . toFixed ( 2 ) + '%' ) + trend ( cell . delta ) ,
155
+ ( ! isFinite ( cell ? .value ) ? '-' : cell . value . toString ( ) ) ,
156
+ ( ! isFinite ( cell ? .delta ) ? '-' : plusSign ( cell . delta ) + cell . delta . toString ( ) ) ,
157
+ ( ! isFinite ( cell ? .prcnt ) ? '-' : plusSign ( cell . prcnt ) + cell . prcnt . toFixed ( 2 ) + '%' + trend ( cell . delta ) ) ,
138
158
] ;
139
159
}
140
160
@@ -146,10 +166,10 @@ function formatCmpMarkdown (rows) {
146
166
{ txt : 'Min' , align : 'right' } ,
147
167
{ txt : '(+/-)' , align : 'right' } ,
148
168
{ txt : '%' , align : 'right' } ,
149
- { txt : 'Avg ' , align : 'right' } ,
169
+ { txt : 'Max ' , align : 'right' } ,
150
170
{ txt : '(+/-)' , align : 'right' } ,
151
171
{ txt : '%' , align : 'right' } ,
152
- { txt : 'Max ' , align : 'right' } ,
172
+ { txt : 'Avg ' , align : 'right' } ,
153
173
{ txt : '(+/-)' , align : 'right' } ,
154
174
{ txt : '%' , align : 'right' } ,
155
175
{ txt : '' } ,
@@ -167,8 +187,8 @@ function formatCmpMarkdown (rows) {
167
187
entry . contract ,
168
188
entry . method ,
169
189
...formatCellMarkdown ( entry . min ) ,
170
- ...formatCellMarkdown ( entry . avg ) ,
171
190
...formatCellMarkdown ( entry . max ) ,
191
+ ...formatCellMarkdown ( entry . avg ) ,
172
192
'' ,
173
193
] . join ( ' | ' ) . trim ( ) ) . join ( '\n' ) ,
174
194
'' ,
0 commit comments