@@ -13,37 +13,27 @@ bp.runState = {
13
13
timesPerAction : { }
14
14
} ;
15
15
16
- bp . Statistics . getStabilityOfSample = function ( sample , confidenceRange ) {
17
- var inRange = 0 ;
18
- sample . forEach ( function ( x ) {
19
- inRange += x <= confidenceRange [ 1 ] && x >= confidenceRange [ 0 ] ? 1 : 0 ;
20
- } )
21
- return Math . round ( ( inRange / sample . length ) * 100 ) / 100 ;
22
-
23
- } ;
24
-
25
- bp . Statistics . getConfidenceRange = function ( mean , confidenceInterval ) {
26
- return [
27
- Math . round ( ( mean - confidenceInterval ) * 100 ) / 100 ,
28
- Math . round ( ( mean + confidenceInterval ) * 100 ) / 100
29
- ] ;
30
- } ;
16
+ bp . Statistics . getMean = function ( sample ) {
17
+ var total = 0 ;
18
+ sample . forEach ( function ( x ) { total += x ; } ) ;
19
+ return total / sample . length ;
20
+ }
31
21
32
22
bp . Statistics . calculateConfidenceInterval = function ( standardDeviation , sampleSize ) {
33
23
var standardError = standardDeviation / Math . sqrt ( sampleSize ) ;
34
- var marginOfError = bp . Statistics . criticalValue * standardError ;
35
- marginOfError = Math . round ( marginOfError * 100 ) / 100 ;
36
- return marginOfError ;
24
+ return bp . Statistics . criticalValue * standardError ;
37
25
} ;
38
26
39
- bp . Statistics . calculateStandardDeviation = function ( sample ) {
40
- var mean = 0 ;
41
- var deviation = 0 ;
42
- sample . forEach ( function ( x ) {
43
- mean += x ;
44
- } ) ;
45
- mean = mean / sample . length ;
27
+ bp . Statistics . calculateRelativeMarginOfError = function ( marginOfError , mean ) {
28
+ /*
29
+ * Converts absolute margin of error to a relative margin of error by
30
+ * converting it to a percentage of the mean.
31
+ */
32
+ return ( marginOfError / mean ) ;
33
+ } ;
46
34
35
+ bp . Statistics . calculateStandardDeviation = function ( sample , mean ) {
36
+ var deviation = 0 ;
47
37
sample . forEach ( function ( x ) {
48
38
deviation += Math . pow ( x - mean , 2 ) ;
49
39
} ) ;
@@ -194,27 +184,20 @@ bp.generateReportModel = function (rawModel) {
194
184
rawModel . gcTimes = rawModel . gcTimes . join ( '<br>' ) ,
195
185
rawModel . garbageTimes = rawModel . garbageTimes . join ( '<br>' ) ,
196
186
rawModel . retainedTimes = rawModel . retainedTimes . join ( '<br>' )
187
+ rawModel . timesConfidenceInterval = ( rawModel . timesConfidenceInterval || 0 ) . toFixed ( 2 ) ;
197
188
return rawModel ;
198
189
} ;
199
190
200
191
bp . generateReportPartial = function ( model ) {
201
192
return bp . infoTemplate ( model ) ;
202
193
} ;
203
194
204
- bp . getAverage = function ( times , gcTimes , garbageTimes , retainedTimes ) {
205
- var timesAvg = 0 ;
206
- var gcAvg = 0 ;
207
- var garbageAvg = 0 ;
208
- var retainedAvg = 0 ;
209
- times . forEach ( function ( x ) { timesAvg += x ; } ) ;
210
- gcTimes . forEach ( function ( x ) { gcAvg += x ; } ) ;
211
- garbageTimes . forEach ( function ( x ) { garbageAvg += x ; } ) ;
212
- retainedTimes . forEach ( function ( x ) { retainedAvg += x ; } ) ;
195
+ bp . getAverages = function ( times , gcTimes , garbageTimes , retainedTimes ) {
213
196
return {
214
- gcTime : gcAvg / gcTimes . length ,
215
- time : timesAvg / times . length ,
216
- garbage : garbageAvg / garbageTimes . length ,
217
- retained : retainedAvg / retainedTimes . length
197
+ gcTime : bp . Statistics . getMean ( gcTimes ) ,
198
+ time : bp . Statistics . getMean ( times ) ,
199
+ garbage : bp . Statistics . getMean ( garbageTimes ) ,
200
+ retained : bp . Statistics . getMean ( retainedTimes )
218
201
} ;
219
202
} ;
220
203
@@ -269,8 +252,7 @@ bp.calcStats = function() {
269
252
tpa = bp . getTimesPerAction ( stepName ) ,
270
253
reportModel ,
271
254
avg ,
272
- timesConfidenceInterval ,
273
- timesConfidenceRange ;
255
+ timesConfidenceInterval ;
274
256
275
257
bp . updateTimes ( tpa , tpa . nextEntry , 'gcTimes' , gcTimeForStep ) ;
276
258
bp . updateTimes ( tpa , tpa . nextEntry , 'garbageTimes' , garbageTimeForStep / 1e3 ) ;
@@ -279,27 +261,22 @@ bp.calcStats = function() {
279
261
280
262
tpa . nextEntry ++ ;
281
263
tpa . nextEntry %= bp . runState . numSamples ;
282
- avg = bp . getAverage (
264
+ avg = bp . getAverages (
283
265
tpa . times ,
284
266
tpa . gcTimes ,
285
267
tpa . garbageTimes ,
286
268
tpa . retainedTimes ) ;
287
269
288
270
timesConfidenceInterval = bp . Statistics . calculateConfidenceInterval (
289
- bp . Statistics . calculateStandardDeviation ( tpa . times ) ,
271
+ bp . Statistics . calculateStandardDeviation ( tpa . times , avg . time ) ,
290
272
tpa . times . length
291
273
) ;
292
- timesConfidenceRange = bp . Statistics . getConfidenceRange (
293
- avg . time ,
294
- timesConfidenceInterval
295
- ) ;
274
+
296
275
reportModel = bp . generateReportModel ( {
297
276
name : stepName ,
298
277
avg : avg ,
299
278
times : tpa . fmtTimes ,
300
- timesConfidenceInterval : timesConfidenceInterval ,
301
- timesConfidenceRange : timesConfidenceRange ,
302
- timesStability : bp . Statistics . getStabilityOfSample ( tpa . times , timesConfidenceRange ) * 100 ,
279
+ timesRelativeMarginOfError : bp . Statistics . calculateRelativeMarginOfError ( timesConfidenceInterval , avg . time ) ,
303
280
gcTimes : tpa . fmtGcTimes ,
304
281
garbageTimes : tpa . fmtGarbageTimes ,
305
282
retainedTimes : tpa . fmtRetainedTimes
0 commit comments