Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit b97fb68

Browse files
author
Marcel Gerber
committed
Simplify PerfUtils.getValueAsString
1 parent 7f1cca4 commit b97fb68

1 file changed

Lines changed: 24 additions & 28 deletions

File tree

src/utils/PerfUtils.js

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -312,36 +312,32 @@ define(function (require, exports, module) {
312312
* @returns {String} a single value, or comma separated values in an array or
313313
* <min(avg)max[standard deviation]> if aggregateStats is set
314314
*/
315-
var getValueAsString = function (entry, aggregateStats) {
316-
if (Array.isArray(entry)) {
317-
var i, values = "", min = entry[0], max = entry[0], avg = 0, sum = 0, sd = 0;
315+
function getValueAsString(entry, aggregateStats) {
316+
if (!Array.isArray(entry)) {
317+
return entry;
318+
}
318319

319-
for (i = 0; i < entry.length; i++) {
320-
sum = sum + entry[i];
321-
values += entry[i];
322-
if (i < entry.length - 1) {
323-
values += ", ";
324-
}
325-
}
326-
if (aggregateStats) {
327-
avg = Math.round(sum / entry.length);
328-
sum = 0;
329-
for (i = 0; i < entry.length; i++) {
330-
sum = sum + Math.pow((entry[i] - avg), 2);
331-
if (entry[i] < min) {
332-
min = entry[i];
333-
} else if (entry[i] > max) {
334-
max = entry[i];
335-
}
336-
}
337-
sd = Math.round(Math.sqrt(sum / entry.length));
338-
return min + "(" + avg + ")" + max + "[" + sd + "]";
339-
}
340-
return values;
320+
if (aggregateStats) {
321+
var sum = 0,
322+
avg,
323+
min = _.min(entry),
324+
max = _.max(entry),
325+
sd,
326+
variationSum = 0;
327+
328+
entry.forEach(function (value) {
329+
sum += value;
330+
});
331+
avg = Math.round(sum / entry.length);
332+
entry.forEach(function (value) {
333+
variationSum += Math.pow(value - avg, 2);
334+
});
335+
sd = Math.round(Math.sqrt(variationSum / entry.length));
336+
return min + "(" + avg + ")" + max + "[" + sd + "]";
341337
} else {
342-
return entry;
338+
return entry.join(", ");
343339
}
344-
};
340+
}
345341

346342
/**
347343
* Returns the performance data as a tab delimited string
@@ -370,7 +366,7 @@ define(function (require, exports, module) {
370366

371367
/**
372368
* Returns the Performance metrics to be logged for health report
373-
* @returns {Object} An object with the helath data logs to be send
369+
* @returns {Object} An object with the health data logs to be sent
374370
*/
375371
function getHealthReport() {
376372
var healthReport = {

0 commit comments

Comments
 (0)