@@ -4,6 +4,8 @@ bp.runState = {
4
4
numSamples : 20 ,
5
5
recentTimePerStep : { } ,
6
6
recentGCTimePerStep : { } ,
7
+ recentGarbagePerStep : { } ,
8
+ recentRetainedMemoryPerStep : { } ,
7
9
timesPerAction : { }
8
10
} ;
9
11
@@ -78,21 +80,40 @@ bp.onSampleRangeChanged = function (evt) {
78
80
} ;
79
81
80
82
bp . runTimedTest = function ( bs ) {
83
+ var startTime ,
84
+ endTime ,
85
+ startGCTime ,
86
+ endGCTime ,
87
+ retainedDelta ,
88
+ garbage ,
89
+ beforeHeap ,
90
+ afterHeap ,
91
+ finalHeap ;
81
92
if ( typeof window . gc === 'function' ) {
82
93
window . gc ( ) ;
83
94
}
84
- var startTime = bp . numMilliseconds ( ) ;
95
+
96
+ beforeHeap = performance . memory . usedJSHeapSize ;
97
+ startTime = bp . numMilliseconds ( ) ;
85
98
bs . fn ( ) ;
86
- var endTime = bp . numMilliseconds ( ) - startTime ;
99
+ endTime = bp . numMilliseconds ( ) - startTime ;
100
+ afterHeap = performance . memory . usedJSHeapSize ;
87
101
88
- var startGCTime = bp . numMilliseconds ( ) ;
102
+ startGCTime = bp . numMilliseconds ( ) ;
89
103
if ( typeof window . gc === 'function' ) {
90
104
window . gc ( ) ;
91
105
}
92
- var endGCTime = bp . numMilliseconds ( ) - startGCTime ;
106
+ endGCTime = bp . numMilliseconds ( ) - startGCTime ;
107
+
108
+ finalHeap = performance . memory . usedJSHeapSize ;
109
+ garbage = Math . abs ( finalHeap - afterHeap ) ;
110
+ retainedDelta = finalHeap - beforeHeap ;
93
111
return {
94
112
time : endTime ,
95
- gcTime : endGCTime
113
+ gcTime : endGCTime ,
114
+ beforeHeap : beforeHeap ,
115
+ garbage : garbage ,
116
+ retainedDelta : retainedDelta
96
117
} ;
97
118
} ;
98
119
@@ -102,6 +123,8 @@ bp.runAllTests = function (done) {
102
123
var testResults = bp . runTimedTest ( bs ) ;
103
124
bp . runState . recentTimePerStep [ bs . name ] = testResults . time ;
104
125
bp . runState . recentGCTimePerStep [ bs . name ] = testResults . gcTime ;
126
+ bp . runState . recentGarbagePerStep [ bs . name ] = testResults . garbage ;
127
+ bp . runState . recentRetainedMemoryPerStep [ bs . name ] = testResults . retainedDelta ;
105
128
} ) ;
106
129
bp . report = bp . calcStats ( ) ;
107
130
bp . writeReport ( bp . report ) ;
@@ -116,31 +139,41 @@ bp.runAllTests = function (done) {
116
139
}
117
140
}
118
141
119
- bp . generateReportPartial = function ( name , avg , fmtTimes , gcTimes ) {
120
- return bp . interpolateHtml (
121
- '<tr class="sampleContainer">' +
122
- '<td>%0</td>' +
123
- '<td class="average">test:%1ms<br>gc:%2ms<br>combined: %3ms</td>' +
124
- '<td><div class="sampleContainer"><div class="testTimeCol">%4</div><div class="testTimeCol">%5</div></div></td>' +
125
- '</tr>' ,
126
- [
127
- name ,
128
- ( '' + avg . time ) . substr ( 0 , 6 ) ,
129
- ( '' + avg . gcTime ) . substr ( 0 , 6 ) ,
130
- ( '' + ( avg . time + avg . gcTime ) ) . substr ( 0 , 6 ) ,
131
- fmtTimes . join ( '<br>' ) ,
132
- gcTimes . join ( '<br>' )
133
- ] ) ;
134
- } ;
135
-
136
- bp . getAverage = function ( times , gcTimes , runState ) {
142
+ bp . generateReportModel = function ( rawModel ) {
143
+ return {
144
+ name : rawModel . name ,
145
+ avg : {
146
+ time : ( '' + rawModel . avg . time ) . substr ( 0 , 6 ) ,
147
+ gcTime : ( '' + rawModel . avg . gcTime ) . substr ( 0 , 6 ) ,
148
+ garbage : ( '' + rawModel . avg . garbage ) . substr ( 0 , 6 ) ,
149
+ retained : ( '' + rawModel . avg . retained ) . substr ( 0 , 6 ) ,
150
+ combinedTime : ( '' + ( rawModel . avg . time + rawModel . avg . gcTime ) ) . substr ( 0 , 6 )
151
+ } ,
152
+ times : rawModel . times . join ( '<br>' ) ,
153
+ gcTimes : rawModel . gcTimes . join ( '<br>' ) ,
154
+ garbageTimes : rawModel . garbageTimes . join ( '<br>' ) ,
155
+ retainedTimes : rawModel . retainedTimes . join ( '<br>' )
156
+ } ;
157
+ } ;
158
+
159
+ bp . generateReportPartial = function ( model ) {
160
+ return bp . infoTemplate ( model ) ;
161
+ } ;
162
+
163
+ bp . getAverage = function ( times , gcTimes , garbageTimes , retainedTimes ) {
137
164
var timesAvg = 0 ;
138
165
var gcAvg = 0 ;
166
+ var garbageAvg = 0 ;
167
+ var retainedAvg = 0 ;
139
168
times . forEach ( function ( x ) { timesAvg += x ; } ) ;
140
169
gcTimes . forEach ( function ( x ) { gcAvg += x ; } ) ;
170
+ garbageTimes . forEach ( function ( x ) { garbageAvg += x ; } ) ;
171
+ retainedTimes . forEach ( function ( x ) { retainedAvg += x ; } ) ;
141
172
return {
142
173
gcTime : gcAvg / gcTimes . length ,
143
- time : timesAvg / times . length
174
+ time : timesAvg / times . length ,
175
+ garbage : garbageAvg / garbageTimes . length ,
176
+ retained : retainedAvg / retainedTimes . length
144
177
} ;
145
178
} ;
146
179
@@ -154,8 +187,12 @@ bp.getTimesPerAction = function(name) {
154
187
tpa = bp . runState . timesPerAction [ name ] = {
155
188
times : [ ] , // circular buffer
156
189
fmtTimes : [ ] ,
157
- fmtGCTimes : [ ] ,
158
190
gcTimes : [ ] ,
191
+ fmtGCTimes : [ ] ,
192
+ garbageTimes : [ ] ,
193
+ fmtGarbageTimes : [ ] ,
194
+ retainedTimes : [ ] ,
195
+ fmtRetainedTimes : [ ] ,
159
196
nextEntry : 0
160
197
}
161
198
}
@@ -177,24 +214,51 @@ bp.calcStats = function() {
177
214
var stepName = bs . name ,
178
215
timeForStep = bp . runState . recentTimePerStep [ stepName ] ,
179
216
gcTimeForStep = bp . runState . recentGCTimePerStep [ stepName ] ,
217
+ garbageTimeForStep = bp . runState . recentGarbagePerStep [ stepName ] ,
218
+ retainedTimeForStep = bp . runState . recentRetainedMemoryPerStep [ stepName ] ,
180
219
tpa = bp . getTimesPerAction ( stepName ) ,
220
+ reportModel ,
181
221
avg ;
182
222
183
- tpa . fmtTimes [ tpa . nextEntry ] = timeForStep . toString ( ) . substr ( 0 , 6 ) ;
184
- tpa . fmtTimes = bp . rightSizeTimes ( tpa . fmtTimes ) ;
185
223
224
+ tpa . gcTimes [ tpa . nextEntry ] = gcTimeForStep ;
225
+ tpa . gcTimes = bp . rightSizeTimes ( tpa . gcTimes ) ;
186
226
tpa . fmtGCTimes [ tpa . nextEntry ] = gcTimeForStep . toString ( ) . substr ( 0 , 6 ) ;
187
227
tpa . fmtGCTimes = bp . rightSizeTimes ( tpa . fmtGCTimes ) ;
188
228
189
- tpa . gcTimes [ tpa . nextEntry ] = gcTimeForStep ;
190
- tpa . gcTimes = bp . rightSizeTimes ( tpa . gcTimes ) ;
191
229
192
- tpa . times [ tpa . nextEntry ++ ] = timeForStep ;
230
+
231
+ tpa . garbageTimes [ tpa . nextEntry ] = garbageTimeForStep / 1e3 ;
232
+ tpa . garbageTimes = bp . rightSizeTimes ( tpa . garbageTimes ) ;
233
+ tpa . fmtGarbageTimes [ tpa . nextEntry ] = ( garbageTimeForStep / 1e3 ) . toFixed ( 3 ) . toString ( ) ;
234
+ tpa . fmtGarbageTimes = bp . rightSizeTimes ( tpa . fmtGarbageTimes ) ;
235
+
236
+ tpa . retainedTimes [ tpa . nextEntry ] = retainedTimeForStep / 1e3 ;
237
+ tpa . retainedTimes = bp . rightSizeTimes ( tpa . retainedTimes ) ;
238
+ tpa . fmtRetainedTimes [ tpa . nextEntry ] = ( retainedTimeForStep / 1e3 ) . toFixed ( 3 ) . toString ( ) ;
239
+ tpa . fmtRetainedTimes = bp . rightSizeTimes ( tpa . fmtRetainedTimes ) ;
240
+
241
+ tpa . times [ tpa . nextEntry ] = timeForStep ;
193
242
tpa . times = bp . rightSizeTimes ( tpa . times ) ;
243
+ tpa . fmtTimes [ tpa . nextEntry ] = timeForStep . toString ( ) . substr ( 0 , 6 ) ;
244
+ tpa . fmtTimes = bp . rightSizeTimes ( tpa . fmtTimes ) ;
194
245
246
+ tpa . nextEntry ++ ;
195
247
tpa . nextEntry %= bp . runState . numSamples ;
196
- avg = bp . getAverage ( tpa . times , tpa . gcTimes ) ;
197
- report += bp . generateReportPartial ( stepName , avg , tpa . fmtTimes , tpa . fmtGCTimes ) ;
248
+ avg = bp . getAverage (
249
+ tpa . times ,
250
+ tpa . gcTimes ,
251
+ tpa . garbageTimes ,
252
+ tpa . retainedTimes ) ;
253
+ reportModel = bp . generateReportModel ( {
254
+ name : stepName ,
255
+ avg : avg ,
256
+ times : tpa . fmtTimes ,
257
+ gcTimes : tpa . fmtGCTimes ,
258
+ garbageTimes : tpa . fmtGarbageTimes ,
259
+ retainedTimes : tpa . fmtRetainedTimes
260
+ } ) ;
261
+ report += bp . generateReportPartial ( reportModel ) ;
198
262
} ) ;
199
263
return report ;
200
264
} ;
@@ -229,6 +293,8 @@ bp.addLinks = function() {
229
293
230
294
bp . addInfo = function ( ) {
231
295
bp . infoDiv = bp . container ( ) . querySelector ( 'tbody.info' ) ;
296
+ bp . infoTemplate = _ . template ( bp . container ( ) . querySelector ( '#infoTemplate' ) . innerHTML ) ;
297
+ console . log ( bp . infoTemplate )
232
298
} ;
233
299
234
300
bp . onDOMContentLoaded = function ( ) {
0 commit comments