Skip to content

Commit 2239844

Browse files
committed
add geomean summary to comparison page iff two exes and one env
1 parent 58fb9f1 commit 2239844

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

codespeed/static/js/comparison.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,98 @@ function getConfiguration() {
2727
};
2828
}
2929

30+
function updateGeomeanSummary(exes, enviros, bens, baseline, chart) {
31+
var $summary = $("#geomean-summary");
32+
if (enviros.length !== 1 || exes.length !== 2 || baseline === "none" ||
33+
chart === "stacked bars" || !compdata) {
34+
$summary.html("");
35+
return;
36+
}
37+
38+
var baselineExe = baseline, baselineEnv = null;
39+
if (baseline.indexOf(':') !== -1) {
40+
var bparts = baseline.split(':');
41+
baselineExe = bparts[0];
42+
baselineEnv = bparts[1];
43+
}
44+
45+
var otherExes = exes.filter(function(e) { return e !== baselineExe; });
46+
if (otherExes.length !== 1) { $summary.html(""); return; }
47+
var otherExe = otherExes[0];
48+
49+
var envId = enviros[0];
50+
var envForBase = baselineEnv !== null ? baselineEnv : envId;
51+
52+
var product = 1, count = 0;
53+
for (var b = 0; b < bens.length; b++) {
54+
var val = compdata[otherExe] && compdata[otherExe][envId]
55+
? compdata[otherExe][envId][bens[b]]
56+
: null;
57+
var baseval = compdata[baselineExe] && compdata[baselineExe][envForBase]
58+
? compdata[baselineExe][envForBase][bens[b]]
59+
: null;
60+
if (val !== null && baseval !== null && baseval !== 0 && val > 0) {
61+
product *= val / baseval;
62+
count++;
63+
}
64+
}
65+
66+
if (count === 0) { $summary.html(""); return; }
67+
68+
var geomean = Math.pow(product, 1 / count);
69+
70+
// Determine whether all selected benchmarks are less-is-better or more-is-better
71+
var lessCount = 0, moreCount = 0;
72+
var benSet = {};
73+
for (var b = 0; b < bens.length; b++) { benSet[bens[b]] = true; }
74+
for (var unit in bench_units) {
75+
var unitBens = bench_units[unit][0];
76+
var unitLess = bench_units[unit][1].indexOf("less") !== -1;
77+
for (var ub = 0; ub < unitBens.length; ub++) {
78+
if (benSet[unitBens[ub]]) {
79+
if (unitLess) { lessCount++; } else { moreCount++; }
80+
}
81+
}
82+
}
83+
84+
var otherLabel = $("label[for='exe_" + otherExe + "']").text().trim();
85+
var baselineLabel = $("label[for='exe_" + baselineExe + "']").text().trim();
86+
if (baselineEnv !== null) {
87+
baselineLabel += ' @ ' + $("label[for='env_" + baselineEnv + "']").text().trim();
88+
}
89+
90+
var suffix;
91+
if (moreCount === 0 && lessCount > 0) {
92+
// All less-is-better: ratio < 1 means faster
93+
if (geomean < 1) {
94+
suffix = ' or <strong>' + (1 / geomean).toFixed(1) + '&times;</strong> faster';
95+
} else {
96+
suffix = ' or <strong>' + geomean.toFixed(1) + '&times;</strong> slower';
97+
}
98+
} else if (lessCount === 0 && moreCount > 0) {
99+
// All more-is-better: ratio > 1 means faster
100+
if (geomean > 1) {
101+
suffix = ' or <strong>' + geomean.toFixed(1) + '&times;</strong> faster';
102+
} else {
103+
suffix = ' or <strong>' + (1 / geomean).toFixed(1) + '&times;</strong> slower';
104+
}
105+
} else {
106+
suffix = ' relative to baseline';
107+
}
108+
109+
$summary.html('The geometric average of ' + count + ' benchmarks for <strong>' +
110+
otherLabel + '</strong> is <strong>' + geomean.toFixed(2) + '</strong>' +
111+
suffix + ' than the baseline <strong>' + baselineLabel + '</strong>');
112+
}
113+
30114
function refreshContent() {
31115
var conf = getConfiguration(),
32116
exes = conf.exe.split(","),
33117
bens = conf.ben.split(","),
34118
enviros = conf.env.split(","),
35119
msg = "";
36120

121+
$("#geomean-summary").html("");
37122
var h = $("#plotwrapper").height();//get height for error message
38123
if (exes[0] === "") {
39124
$("#plotwrapper").html('<p class="warning">No executables selected</p>');
@@ -87,6 +172,7 @@ function refreshContent() {
87172
plotcounter++;
88173
renderComparisonPlot(plotid, unit, benchmarks, exes, enviros, conf.bas, conf.chart, conf.hor);
89174
}
175+
updateGeomeanSummary(exes, enviros, bens, conf.bas, conf.chart);
90176
});
91177
}
92178

codespeed/templates/codespeed/comparison.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<a id="permalink" href="#">Permalink</a>
8181
<a id="exportcsv" href="#">Export CSV</a>
8282
</div>
83+
<div id="geomean-summary" style="padding: 6px 10px; font-size: 14px;"></div>
8384
<div id="content" class="clearfix">
8485
<div id="plotwrapper"></div>
8586
</div>

0 commit comments

Comments
 (0)