Skip to content

Commit

Permalink
Merge pull request #51 from Lysxia/unit-render
Browse files Browse the repository at this point in the history
Improve rendering of values
  • Loading branch information
nomeata authored Nov 20, 2017
2 parents f63cd90 + 2f9bb0b commit 5ac478a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 deletions.
14 changes: 7 additions & 7 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ <h1>Benchmarks</h1>
<div class="panel-heading" role="tab" id="heading-{{@index}}">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" href="#table-{{@index}}">
{{groupName}}
{{groupName}}{{#if unitFull}}, {{unitFull}}{{/if}}
</a>
</h4>
</div>
Expand Down Expand Up @@ -471,7 +471,7 @@ <h2>
<div class="panel-heading" role="tab" id="heading-{{@index}}">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" href="#table-{{@index}}">
{{groupName}}
{{groupName}}{{#if unitFull}}, {{unitFull}}{{/if}}
<span class="stats pull-right">
{{> summary-icons groupStats}}
<span class="indicator-toggled glyphicon glyphicon-chevron-down text-grey"/>
Expand All @@ -488,9 +488,9 @@ <h4 class="panel-title">
<tr>
<th class="col-xs-5">Benchmark name</th>
<th class="col-xs-2 text-right">previous</th>
<th class="col-xs-2 text-right">change</th>
<th class="col-xs-2 text-right">now</th>
<th class="col-xs-1 text-left"></th>
<th class="col-xs-2 text-right">change</th>
</tr>
</thead>
<tbody>
Expand All @@ -507,9 +507,9 @@ <h4 class="panel-title">
</a>
</td>
<td class="text-right">{{previous}}</td>
<td class="text-right">{{change}}</td>
<td class="text-right">{{value}}</td>
<td class="text-left">{{unit}}</td>
<td class="text-right">{{change}}</td>
</tr>
{{/each}}
</tbody>
Expand Down Expand Up @@ -579,7 +579,7 @@ <h2>
<div class="panel-heading" role="tab" id="heading-{{@index}}">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" href="#table-{{@index}}">
{{groupName}}
{{groupName}}{{#if unitFull}}, {{unitFull}}{{/if}}
<span class="stats pull-right">
{{> summary-icons groupStats}}
<span class="indicator-toggled glyphicon glyphicon-chevron-down text-grey"/>
Expand All @@ -596,9 +596,9 @@ <h4 class="panel-title">
<tr>
<th class="col-xs-5">Benchmark name</th>
<th class="col-xs-2 text-right">previous</th>
<th class="col-xs-2 text-right">change</th>
<th class="col-xs-2 text-right">now</th>
<th class="col-xs-1 text-right"></th>
<th class="col-xs-2 text-right">change</th>
</tr>
</thead>
<tbody>
Expand All @@ -615,9 +615,9 @@ <h4 class="panel-title">
</a>
</td>
<td class="text-right">{{previous}}</td>
<td class="text-right">{{change}}</td>
<td class="text-right">{{value}}</td>
<td class="text-left">{{unit}}</td>
<td class="text-right">{{change}}</td>
</tr>
{{/each}}
</tbody>
Expand Down
38 changes: 37 additions & 1 deletion site/js/gipeda.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ function setting_for(name) {
var benchSettings = {
smallerIsBetter: true,
unit: "",
unitFull: "",
rescalable: false,
type: "integral",
group: "",
threshold: 3,
Expand All @@ -358,6 +360,32 @@ function setting_for(name) {
return benchSettings;
}

var unitPrefix = [["G", 9], ["M", 6], ["k", 3], ["", 0], ["m", -3], ["u", -6], ["n", -9]]

// Make numbers more human-readable.
function rescale(s, res) {
// Only rescale nonzero rescalable numbers.
if (!s.rescalable || (!res.previous && !res.value)) { return; }

// If the result is a comparison, i.e., contains both res.previous and
// res.value, then both are rescaled together.
for (var i = 0; i < unitPrefix.length; i++) {
var magnitude = Math.pow(10, unitPrefix[i][1]);
if (i == unitPrefix.length - 1 // Fallback to nano
|| ( (res.previous === null || res.previous >= magnitude)
&& (res.value === null || res.value >= magnitude))) {
if (res.previous !== null) { res.previous = res.previous / magnitude; }
if (res.value !== null) { res.value = res.value / magnitude; }
res.unit = unitPrefix[i][0] + s.unit;
break;
}
}

if (s.type == "float" || magnitude > 1) {
if (res.previous !== null) { res.previous = res.previous.toFixed(2); }
if (res.value !== null) { res.value = res.value.toFixed(2); }
}
}

// The following logic should be kept in sync with toResult in ReportTypes.hs
function compareResults (res1, res2) {
Expand Down Expand Up @@ -425,6 +453,8 @@ function compareResults (res1, res2) {
}
}

rescale(s, res);

return res;
}

Expand All @@ -434,7 +464,7 @@ function singleResult (res) {
var name = res.name;
var s = setting_for(name);

return {
var newRes = {
name: name,
previous: null,
value: res.value,
Expand All @@ -443,6 +473,10 @@ function singleResult (res) {
changeType: "Boring",
change: "",
};

rescale(s, newRes);

return newRes;
}

// Some views require the data to be prepared in ways that are
Expand All @@ -466,6 +500,8 @@ function calculate_groups(rev1, rev2) {
}).filter(function (br) {return br;});
return {
groupName: group.groupName || "Benchmarks",
unit: group.groupUnit,
unitFull: group.groupUnitFull,
benchResults: benchmarks,
groupStats: groupStats(benchmarks),
};
Expand Down
15 changes: 10 additions & 5 deletions src/BenchNames.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module BenchNames where

import qualified Data.ByteString.Lazy as BS
import Data.Aeson
import Control.Applicative
import Control.Monad
import qualified Data.Map as M
import qualified Data.Text as T
Expand All @@ -19,12 +20,16 @@ benchNamesMain benchNames = do
settings <- S.readSettings "gipeda.yaml"

let groups =
map (uncurry BenchGroup) $
sort $
sortOn (liftA2 (,) groupName groupMembers) $
map (\(name, (s, bns)) -> BenchGroup
{ groupName = name
, groupMembers = bns
, groupUnitFull = S.unitFull s
}) $
M.toList $
M.map sort $
M.fromListWith (++)
[ (S.group s, [bn])
M.map (fmap sort) $
M.fromListWith (\(s, bns) (_, bns') -> (s, bns ++ bns'))
[ (S.group s, (s, [bn]))
| bn <- benchNames
, let s = S.benchSettings settings bn
]
Expand Down
9 changes: 8 additions & 1 deletion src/BenchmarkSettings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type BenchName = String
data BenchSettings = BenchSettings
{ smallerIsBetter :: Bool
, unit :: String
, unitFull :: Maybe String
, rescalable :: Bool
, numberType :: NumberType
, group :: String
, threshold :: Double
Expand All @@ -32,8 +34,9 @@ data BenchSettings = BenchSettings
deriving (Show, Generic)
instance ToJSON BenchSettings

-- Keep in sync with setting_for() in gipeda.js
defaultBenchSettings :: BenchSettings
defaultBenchSettings = BenchSettings True "" IntegralNT "" 3 True
defaultBenchSettings = BenchSettings True "" Nothing False IntegralNT "" 3 True

newtype S = S { unS :: BenchName -> BenchSettings }
newtype SM = SM (BenchName -> (BenchSettings -> BenchSettings))
Expand All @@ -60,6 +63,8 @@ instance FromJSON SM where
m <- o .: "match"
mt <- o .:? "type"
mu <- o .:? "unit"
muf <- o.:? "unitFull"
mr <- o .:? "rescalable"
mg <- o .:? "group"
ms <- o .:? "smallerIsBetter"
mth <- o .:? "threshold"
Expand All @@ -68,6 +73,8 @@ instance FromJSON SM where
if n `matches` m then
b { numberType = fromMaybe (numberType b) mt
, unit = fromMaybe (unit b) mu
, unitFull = muf
, rescalable = fromMaybe (rescalable b) mr
, group = fromMaybe (group b) mg
, smallerIsBetter = fromMaybe (smallerIsBetter b) ms
, threshold = fromMaybe (threshold b) mth
Expand Down
1 change: 1 addition & 0 deletions src/ReportTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ instance FromJSON ChangeType
data BenchGroup = BenchGroup
{ groupName :: String
, groupMembers :: [BenchName]
, groupUnitFull :: Maybe String
}
deriving (Generic)
instance ToJSON BenchGroup
Expand Down

0 comments on commit 5ac478a

Please sign in to comment.