@@ -8,10 +8,7 @@ var bp = window.bp = {
8
8
runState : {
9
9
iterations : 0 ,
10
10
numSamples : 20 ,
11
- recentTimePerStep : { } ,
12
- recentGCTimePerStep : { } ,
13
- recentGarbagePerStep : { } ,
14
- recentRetainedMemoryPerStep : { }
11
+ recentResult : { }
15
12
}
16
13
} ,
17
14
Document : { } ,
@@ -106,10 +103,7 @@ bp.Runner.runAllTests = function (done) {
106
103
if ( bp . Runner . runState . iterations -- ) {
107
104
bp . steps . forEach ( function ( bs ) {
108
105
var testResults = bp . Runner . runTimedTest ( bs ) ;
109
- bp . Runner . runState . recentTimePerStep [ bs . name ] = testResults . time ;
110
- bp . Runner . runState . recentGCTimePerStep [ bs . name ] = testResults . gcTime ;
111
- bp . Runner . runState . recentGarbagePerStep [ bs . name ] = testResults . garbage ;
112
- bp . Runner . runState . recentRetainedMemoryPerStep [ bs . name ] = testResults . retainedDelta ;
106
+ bp . Runner . runState . recentResult [ bs . name ] = testResults ;
113
107
} ) ;
114
108
bp . Report . markup = bp . Report . calcStats ( ) ;
115
109
bp . Document . writeReport ( bp . Report . markup ) ;
@@ -129,7 +123,7 @@ bp.Runner.runTimedTest = function (bs) {
129
123
endTime ,
130
124
startGCTime ,
131
125
endGCTime ,
132
- retainedDelta ,
126
+ retainedMemory ,
133
127
garbage ,
134
128
beforeHeap ,
135
129
afterHeap ,
@@ -152,34 +146,18 @@ bp.Runner.runTimedTest = function (bs) {
152
146
153
147
finalHeap = performance . memory . usedJSHeapSize ;
154
148
garbage = Math . abs ( finalHeap - afterHeap ) ;
155
- retainedDelta = finalHeap - beforeHeap ;
149
+ retainedMemory = finalHeap - beforeHeap ;
156
150
return {
157
- time : endTime ,
151
+ testTime : endTime ,
158
152
gcTime : endGCTime ,
159
153
beforeHeap : beforeHeap ,
160
154
garbage : garbage ,
161
- retainedDelta : retainedDelta
155
+ retainedMemory : retainedMemory
162
156
} ;
163
157
} ;
164
158
165
- bp . Report . generateReportModel = function ( rawModel ) {
166
- rawModel . avg = {
167
- time : ( '' + rawModel . avg . time ) . substr ( 0 , 6 ) ,
168
- gcTime : ( '' + rawModel . avg . gcTime ) . substr ( 0 , 6 ) ,
169
- garbage : ( '' + rawModel . avg . garbage ) . substr ( 0 , 6 ) ,
170
- retained : ( '' + rawModel . avg . retained ) . substr ( 0 , 6 ) ,
171
- combinedTime : ( '' + ( rawModel . avg . time + rawModel . avg . gcTime ) ) . substr ( 0 , 6 )
172
- } ;
173
- rawModel . times = rawModel . times . join ( '<br>' ) ,
174
- rawModel . gcTimes = rawModel . gcTimes . join ( '<br>' ) ,
175
- rawModel . garbageTimes = rawModel . garbageTimes . join ( '<br>' ) ,
176
- rawModel . retainedTimes = rawModel . retainedTimes . join ( '<br>' )
177
- rawModel . timesConfidenceInterval = ( rawModel . timesConfidenceInterval || 0 ) . toFixed ( 2 ) ;
178
- return rawModel ;
179
- } ;
180
-
181
159
bp . Report . generatePartial = function ( model ) {
182
- return bp . infoTemplate ( model ) ;
160
+ return bp . Document . infoTemplate ( model ) ;
183
161
} ;
184
162
185
163
bp . Document . writeReport = function ( reportContent ) {
@@ -190,14 +168,10 @@ bp.Report.getTimesPerAction = function(name) {
190
168
var tpa = bp . Report . timesPerAction [ name ] ;
191
169
if ( ! tpa ) {
192
170
tpa = bp . Report . timesPerAction [ name ] = {
193
- times : [ ] , // circular buffer
194
- fmtTimes : [ ] ,
171
+ testTimes : [ ] , // circular buffer
195
172
gcTimes : [ ] ,
196
- fmtGcTimes : [ ] ,
197
- garbageTimes : [ ] ,
198
- fmtGarbageTimes : [ ] ,
199
- retainedTimes : [ ] ,
200
- fmtRetainedTimes : [ ] ,
173
+ garbageCount : [ ] ,
174
+ retainedCount : [ ] ,
201
175
nextEntry : 0
202
176
}
203
177
}
@@ -214,58 +188,42 @@ bp.Report.rightSizeTimes = function(times) {
214
188
} ;
215
189
216
190
bp . Report . updateTimes = function ( tpa , index , reference , recentTime ) {
217
- var fmtKey = 'fmt' + reference . charAt ( 0 ) . toUpperCase ( ) + reference . slice ( 1 ) ;
218
191
tpa [ reference ] [ index ] = recentTime ;
219
192
tpa [ reference ] = bp . Report . rightSizeTimes ( tpa [ reference ] ) ;
220
- tpa [ fmtKey ] [ index ] = recentTime . toString ( ) . substr ( 0 , 6 ) ;
221
- tpa [ fmtKey ] = bp . Report . rightSizeTimes ( tpa [ fmtKey ] ) ;
222
193
} ;
223
194
224
195
bp . Report . calcStats = function ( ) {
225
196
var report = '' ;
226
197
bp . steps . forEach ( function ( bs ) {
227
- var stepName = bs . name ,
228
- timeForStep = bp . Runner . runState . recentTimePerStep [ stepName ] ,
229
- gcTimeForStep = bp . Runner . runState . recentGCTimePerStep [ stepName ] ,
230
- garbageTimeForStep = bp . Runner . runState . recentGarbagePerStep [ stepName ] ,
231
- retainedTimeForStep = bp . Runner . runState . recentRetainedMemoryPerStep [ stepName ] ,
232
- tpa = bp . Report . getTimesPerAction ( stepName ) ,
233
- reportModel ,
234
- avg ,
235
- timesConfidenceInterval ,
236
- timesStandardDeviation ;
237
-
238
- bp . Report . updateTimes ( tpa , tpa . nextEntry , 'gcTimes' , gcTimeForStep ) ;
239
- bp . Report . updateTimes ( tpa , tpa . nextEntry , 'garbageTimes' , garbageTimeForStep / 1e3 ) ;
240
- bp . Report . updateTimes ( tpa , tpa . nextEntry , 'retainedTimes' , retainedTimeForStep / 1e3 ) ;
241
- bp . Report . updateTimes ( tpa , tpa . nextEntry , 'times' , timeForStep ) ;
198
+ var recentResult = bp . Runner . runState . recentResult [ bs . name ] ,
199
+ tpa = bp . Report . getTimesPerAction ( bs . name ) ;
200
+
201
+ bp . Report . updateTimes ( tpa , tpa . nextEntry , 'gcTimes' , recentResult . gcTime ) ;
202
+ bp . Report . updateTimes ( tpa , tpa . nextEntry , 'garbageCount' , recentResult . garbage / 1e3 ) ;
203
+ bp . Report . updateTimes ( tpa , tpa . nextEntry , 'retainedCount' , recentResult . retainedMemory / 1e3 ) ;
204
+ bp . Report . updateTimes ( tpa , tpa . nextEntry , 'testTimes' , recentResult . testTime ) ;
242
205
243
206
tpa . nextEntry ++ ;
244
207
tpa . nextEntry %= bp . Runner . runState . numSamples ;
245
- avg = {
246
- gcTime : bp . Statistics . getMean ( tpa . gcTimes ) ,
247
- time : bp . Statistics . getMean ( tpa . times ) ,
248
- garbage : bp . Statistics . getMean ( tpa . garbageTimes ) ,
249
- retained : bp . Statistics . getMean ( tpa . retainedTimes )
208
+
209
+ var meanTestTime = bp . Statistics . getMean ( tpa . testTimes ) ;
210
+ var testTimesStdDev = bp . Statistics . calculateStandardDeviation ( tpa . testTimes , meanTestTime ) ;
211
+ var avgGCTime = bp . Statistics . getMean ( tpa . gcTimes ) ;
212
+ var avg = {
213
+ gcTime : avgGCTime ,
214
+ testTime : meanTestTime ,
215
+ combinedTime : meanTestTime + avgGCTime ,
216
+ garbage : bp . Statistics . getMean ( tpa . garbageCount ) ,
217
+ retained : bp . Statistics . getMean ( tpa . retainedCount ) ,
218
+ testTimesStdDev : testTimesStdDev ,
219
+ coefficientOfVariation : bp . Statistics . calculateCoefficientOfVariation ( testTimesStdDev , meanTestTime )
250
220
} ;
251
221
252
- timesStandardDeviation = bp . Statistics . calculateStandardDeviation ( tpa . times , avg . time ) ;
253
- timesConfidenceInterval = bp . Statistics . calculateConfidenceInterval (
254
- timesStandardDeviation ,
255
- tpa . times . length
256
- ) ;
257
-
258
- reportModel = bp . Report . generateReportModel ( {
259
- name : stepName ,
260
- avg : avg ,
261
- times : tpa . fmtTimes ,
262
- timesStandardDeviation : timesStandardDeviation ,
263
- coefficientOfVariation : bp . Statistics . calculateCoefficientOfVariation ( timesStandardDeviation , avg . time ) ,
264
- timesRelativeMarginOfError : bp . Statistics . calculateRelativeMarginOfError ( timesConfidenceInterval , avg . time ) ,
265
- gcTimes : tpa . fmtGcTimes ,
266
- garbageTimes : tpa . fmtGarbageTimes ,
267
- retainedTimes : tpa . fmtRetainedTimes
268
- } ) ;
222
+ var reportModel = _ . clone ( tpa ) ;
223
+ reportModel . name = bs . name ;
224
+ reportModel . avg = avg ;
225
+ reportModel . testTimes = tpa . testTimes ;
226
+
269
227
report += bp . Report . generatePartial ( reportModel ) ;
270
228
} ) ;
271
229
return report ;
@@ -291,10 +249,10 @@ bp.Document.onSampleInputChanged = function (evt) {
291
249
} ;
292
250
293
251
bp . Document . container = function ( ) {
294
- if ( ! bp . _container ) {
295
- bp . _container = document . querySelector ( '#benchmarkContainer' ) ;
252
+ if ( ! bp . Document . _container ) {
253
+ bp . Document . _container = document . querySelector ( '#benchmarkContainer' ) ;
296
254
}
297
- return bp . _container ;
255
+ return bp . Document . _container ;
298
256
}
299
257
300
258
bp . Document . addButton = function ( reference , handler ) {
@@ -325,11 +283,12 @@ bp.Document.addLinks = function() {
325
283
bp . Document . addInfo = function ( ) {
326
284
bp . Document . infoDiv = bp . Document . container ( ) . querySelector ( 'tbody.info' ) ;
327
285
if ( bp . Document . infoDiv ) {
328
- bp . infoTemplate = _ . template ( bp . Document . container ( ) . querySelector ( '#infoTemplate' ) . innerHTML ) ;
286
+ bp . Document . infoTemplate = _ . template ( bp . Document . container ( ) . querySelector ( '#infoTemplate' ) . innerHTML ) ;
329
287
}
330
288
} ;
331
289
332
290
bp . Document . onDOMContentLoaded = function ( ) {
291
+ if ( ! bp . Document . container ( ) ) return ;
333
292
bp . Document . addLinks ( ) ;
334
293
bp . Document . addButton ( 'loopBtn' , bp . Runner . loopBenchmark ) ;
335
294
bp . Document . addButton ( 'onceBtn' , bp . Runner . onceBenchmark ) ;
0 commit comments