@@ -3,6 +3,7 @@ bp.steps = window.benchmarkSteps = [];
3
3
bp . runState = {
4
4
numSamples : 10 ,
5
5
recentTimePerStep : { } ,
6
+ recentGCTimePerStep : { } ,
6
7
timesPerAction : { }
7
8
} ;
8
9
@@ -82,13 +83,25 @@ bp.runTimedTest = function (bs) {
82
83
}
83
84
var startTime = bp . numMilliseconds ( ) ;
84
85
bs . fn ( ) ;
85
- return bp . numMilliseconds ( ) - startTime ;
86
+ var endTime = bp . numMilliseconds ( ) - startTime ;
87
+
88
+ var startGCTime = bp . numMilliseconds ( ) ;
89
+ if ( typeof window . gc === 'function' ) {
90
+ window . gc ( ) ;
91
+ }
92
+ var endGCTime = bp . numMilliseconds ( ) - startGCTime ;
93
+ return {
94
+ time : endTime ,
95
+ gcTime : endGCTime
96
+ } ;
86
97
} ;
87
98
88
99
bp . runAllTests = function ( done ) {
89
100
if ( bp . runState . iterations -- ) {
90
101
bp . steps . forEach ( function ( bs ) {
91
- bp . runState . recentTimePerStep [ bs . name ] = bp . runTimedTest ( bs ) ;
102
+ var testResults = bp . runTimedTest ( bs ) ;
103
+ bp . runState . recentTimePerStep [ bs . name ] = testResults . time ;
104
+ bp . runState . recentGCTimePerStep [ bs . name ] = testResults . gcTime ;
92
105
} ) ;
93
106
bp . report = bp . calcStats ( ) ;
94
107
bp . writeReport ( bp . report ) ;
@@ -103,20 +116,28 @@ bp.runAllTests = function (done) {
103
116
}
104
117
}
105
118
106
- bp . generateReportPartial = function ( name , avg , times ) {
119
+ bp . generateReportPartial = function ( name , avg , fmtTimes , gcTimes ) {
107
120
return bp . interpolateHtml (
108
- '<tr><td>%0</td><td class="average">%1ms</td><td>[%2]ms </td></tr>' ,
121
+ '<tr><td>%0</td><td class="average">test: %1ms<br>gc:%2ms<br>combined: %3ms< /td><td>%4</td><td>%5 </td></tr>' ,
109
122
[
110
123
name ,
111
- ( '' + avg ) . substr ( 0 , 6 ) ,
112
- times . join ( ', ' )
124
+ ( '' + avg . time ) . substr ( 0 , 6 ) ,
125
+ ( '' + avg . gcTime ) . substr ( 0 , 6 ) ,
126
+ ( '' + ( avg . time + avg . gcTime ) ) . substr ( 0 , 6 ) ,
127
+ fmtTimes . join ( '<br>' ) ,
128
+ gcTimes . join ( '<br>' )
113
129
] ) ;
114
130
} ;
115
131
116
- bp . getAverage = function ( times , runState ) {
117
- var avg = 0 ;
118
- times . forEach ( function ( x ) { avg += x ; } ) ;
119
- return avg / times . length ;
132
+ bp . getAverage = function ( times , gcTimes , runState ) {
133
+ var timesAvg = 0 ;
134
+ var gcAvg = 0 ;
135
+ times . forEach ( function ( x ) { timesAvg += x ; } ) ;
136
+ gcTimes . forEach ( function ( x ) { gcAvg += x ; } ) ;
137
+ return {
138
+ gcTime : gcAvg / gcTimes . length ,
139
+ time : timesAvg / times . length
140
+ } ;
120
141
} ;
121
142
122
143
bp . writeReport = function ( reportContent ) {
@@ -129,6 +150,8 @@ bp.getTimesPerAction = function(name) {
129
150
tpa = bp . runState . timesPerAction [ name ] = {
130
151
times : [ ] , // circular buffer
131
152
fmtTimes : [ ] ,
153
+ fmtGCTimes : [ ] ,
154
+ gcTimes : [ ] ,
132
155
nextEntry : 0
133
156
}
134
157
}
@@ -149,17 +172,25 @@ bp.calcStats = function() {
149
172
bp . steps . forEach ( function ( bs ) {
150
173
var stepName = bs . name ,
151
174
timeForStep = bp . runState . recentTimePerStep [ stepName ] ,
175
+ gcTimeForStep = bp . runState . recentGCTimePerStep [ stepName ] ,
152
176
tpa = bp . getTimesPerAction ( stepName ) ,
153
177
avg ;
154
178
155
- tpa . fmtTimes [ tpa . nextEntry ] = ( '' + timeForStep ) . substr ( 0 , 6 ) ;
179
+ tpa . fmtTimes [ tpa . nextEntry ] = timeForStep . toString ( ) . substr ( 0 , 6 ) ;
156
180
tpa . fmtTimes = bp . rightSizeTimes ( tpa . fmtTimes ) ;
181
+
182
+ tpa . fmtGCTimes [ tpa . nextEntry ] = gcTimeForStep . toString ( ) . substr ( 0 , 6 ) ;
183
+ tpa . fmtGCTimes = bp . rightSizeTimes ( tpa . fmtGCTimes ) ;
184
+
185
+ tpa . gcTimes [ tpa . nextEntry ] = gcTimeForStep ;
186
+ tpa . gcTimes = bp . rightSizeTimes ( tpa . gcTimes ) ;
187
+
157
188
tpa . times [ tpa . nextEntry ++ ] = timeForStep ;
158
189
tpa . times = bp . rightSizeTimes ( tpa . times ) ;
159
- tpa . nextEntry %= bp . runState . numSamples ;
160
- avg = bp . getAverage ( tpa . times , bp . runState ) ;
161
190
162
- report += bp . generateReportPartial ( stepName , avg , tpa . fmtTimes ) ;
191
+ tpa . nextEntry %= bp . runState . numSamples ;
192
+ avg = bp . getAverage ( tpa . times , tpa . gcTimes ) ;
193
+ report += bp . generateReportPartial ( stepName , avg , tpa . fmtTimes , tpa . fmtGCTimes ) ;
163
194
} ) ;
164
195
return report ;
165
196
} ;
0 commit comments