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

Commit

Permalink
Merge pull request #11381 from adobe/marcel/getvalueasstring-simplify
Browse files Browse the repository at this point in the history
Simplify PerfUtils.getValueAsString
  • Loading branch information
abose committed Jul 12, 2015
2 parents 7f1cca4 + b97fb68 commit 217de11
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/utils/PerfUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,36 +312,32 @@ define(function (require, exports, module) {
* @returns {String} a single value, or comma separated values in an array or
* <min(avg)max[standard deviation]> if aggregateStats is set
*/
var getValueAsString = function (entry, aggregateStats) {
if (Array.isArray(entry)) {
var i, values = "", min = entry[0], max = entry[0], avg = 0, sum = 0, sd = 0;
function getValueAsString(entry, aggregateStats) {
if (!Array.isArray(entry)) {
return entry;
}

for (i = 0; i < entry.length; i++) {
sum = sum + entry[i];
values += entry[i];
if (i < entry.length - 1) {
values += ", ";
}
}
if (aggregateStats) {
avg = Math.round(sum / entry.length);
sum = 0;
for (i = 0; i < entry.length; i++) {
sum = sum + Math.pow((entry[i] - avg), 2);
if (entry[i] < min) {
min = entry[i];
} else if (entry[i] > max) {
max = entry[i];
}
}
sd = Math.round(Math.sqrt(sum / entry.length));
return min + "(" + avg + ")" + max + "[" + sd + "]";
}
return values;
if (aggregateStats) {
var sum = 0,
avg,
min = _.min(entry),
max = _.max(entry),
sd,
variationSum = 0;

entry.forEach(function (value) {
sum += value;
});
avg = Math.round(sum / entry.length);
entry.forEach(function (value) {
variationSum += Math.pow(value - avg, 2);
});
sd = Math.round(Math.sqrt(variationSum / entry.length));
return min + "(" + avg + ")" + max + "[" + sd + "]";
} else {
return entry;
return entry.join(", ");
}
};
}

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

/**
* Returns the Performance metrics to be logged for health report
* @returns {Object} An object with the helath data logs to be send
* @returns {Object} An object with the health data logs to be sent
*/
function getHealthReport() {
var healthReport = {
Expand Down

0 comments on commit 217de11

Please sign in to comment.