Skip to content

Commit 29c6343

Browse files
committed
chore(benchmark): reduce code duplication with updateTimes()
1 parent afe5581 commit 29c6343

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

benchmark/web/bp.js

+15-25
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bp.getTimesPerAction = function(name) {
188188
times: [], // circular buffer
189189
fmtTimes: [],
190190
gcTimes: [],
191-
fmtGCTimes: [],
191+
fmtGcTimes: [],
192192
garbageTimes: [],
193193
fmtGarbageTimes: [],
194194
retainedTimes: [],
@@ -208,6 +208,15 @@ bp.rightSizeTimes = function(times) {
208208
return times;
209209
};
210210

211+
bp.updateTimes = function(tpa, index, reference, recentTime) {
212+
var fmtKey = 'fmt' + reference.charAt(0).toUpperCase() + reference.slice(1);
213+
tpa[reference][index] = recentTime;
214+
tpa[reference] = bp.rightSizeTimes(tpa[reference]);
215+
tpa[fmtKey][index] = recentTime.toString().substr(0, 6);
216+
tpa[fmtKey] = bp.rightSizeTimes(tpa[fmtKey]);
217+
218+
};
219+
211220
bp.calcStats = function() {
212221
var report = '';
213222
bp.steps.forEach(function(bs) {
@@ -220,28 +229,10 @@ bp.calcStats = function() {
220229
reportModel,
221230
avg;
222231

223-
224-
tpa.gcTimes[tpa.nextEntry] = gcTimeForStep;
225-
tpa.gcTimes = bp.rightSizeTimes(tpa.gcTimes);
226-
tpa.fmtGCTimes[tpa.nextEntry] = gcTimeForStep.toString().substr(0, 6);
227-
tpa.fmtGCTimes = bp.rightSizeTimes(tpa.fmtGCTimes);
228-
229-
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;
242-
tpa.times = bp.rightSizeTimes(tpa.times);
243-
tpa.fmtTimes[tpa.nextEntry] = timeForStep.toString().substr(0, 6);
244-
tpa.fmtTimes = bp.rightSizeTimes(tpa.fmtTimes);
232+
bp.updateTimes(tpa, tpa.nextEntry, 'gcTimes', gcTimeForStep);
233+
bp.updateTimes(tpa, tpa.nextEntry, 'garbageTimes', garbageTimeForStep / 1e3);
234+
bp.updateTimes(tpa, tpa.nextEntry, 'retainedTimes', retainedTimeForStep / 1e3);
235+
bp.updateTimes(tpa, tpa.nextEntry, 'times', timeForStep);
245236

246237
tpa.nextEntry++;
247238
tpa.nextEntry %= bp.runState.numSamples;
@@ -254,7 +245,7 @@ bp.calcStats = function() {
254245
name: stepName,
255246
avg: avg,
256247
times: tpa.fmtTimes,
257-
gcTimes: tpa.fmtGCTimes,
248+
gcTimes: tpa.fmtGcTimes,
258249
garbageTimes: tpa.fmtGarbageTimes,
259250
retainedTimes: tpa.fmtRetainedTimes
260251
});
@@ -294,7 +285,6 @@ bp.addLinks = function() {
294285
bp.addInfo = function() {
295286
bp.infoDiv = bp.container().querySelector('tbody.info');
296287
bp.infoTemplate = _.template(bp.container().querySelector('#infoTemplate').innerHTML);
297-
console.log(bp.infoTemplate)
298288
};
299289

300290
bp.onDOMContentLoaded = function() {

benchmark/web/bp.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ describe('bp', function() {
394394
fakeStep: {
395395
times: [3,7],
396396
fmtTimes: ['3', '7'],
397-
fmtGCTimes: ['1','3'],
397+
fmtGcTimes: ['1','3'],
398398
garbageTimes: [50,50],
399399
fmtGarbageTimes: ['50','50'],
400400
retainedTimes: [25,25],

0 commit comments

Comments
 (0)