Permalink
Browse files

adding relative group percentages

  • Loading branch information...
1 parent 567c992 commit 021814ba2f792f40bd53bc9644a8414dbdcfac69 @makeusabrew committed Dec 21, 2011
Showing with 47 additions and 24 deletions.
  1. +2 −2 HtmlReporter.php
  2. +34 −13 TestRunner.php
  3. +11 −9 template.view.php
View
@@ -7,7 +7,7 @@ public function run() {
echo $this->render("template.view.php", array(
'profiles' => $data['profiles'],
'meta' => $data['meta'],
- 'url' => 'https://github.com/makeusabrew/phpperf/tree/master/profiles/',
+ 'url' => 'https://github.com/makeusabrew/phpperf/',
));
}
@@ -16,7 +16,7 @@ protected function highlight($str) {
}
protected function microformat($value) {
- return round(($value * 1000000), 3)." μs";
+ return (($value * 1000000))." μs";
}
protected function render($tpl, $vars) {
View
@@ -93,7 +93,23 @@ public function run() {
$results[] = $result;
$suiteMean += $mean;
$suiteProfiles ++;
- $suiteMedian[] = $rawMean;
+ $suiteMedian[] = $mean;
+ }
+
+ /*
+ $groupMedian = array();
+ foreach ($results as $result) {
+ $groupMedian[] = $result['mean'];
+ }
+ */
+
+ $groupMedian = $this->getMedian(array_map(function($v) {
+ return $v['mean'];
+ }, $results));
+
+ foreach($results as $i => $result) {
+ $result['pc_group'] = (($result['mean'] / $groupMedian) * 100) - 100;
+ $results[$i] = $result;
}
$this->profiles[] = array(
@@ -103,23 +119,13 @@ public function run() {
);
}
- sort($suiteMedian);
- if (count($suiteMedian) % 2 == 0) {
- // even, take middle two
- $top = count($suiteMedian) / 2;
- $bottom = $top - 1;
-
- $suiteMedian = ($suiteMedian[$bottom] + $suiteMedian[$top]) / 2.0;
- } else {
- $idx = floor(count($suiteMedian) / 2);
- $suiteMedian = $suiteMedian[$idx];
- }
+ $suiteMedian = $this->getMedian($suiteMedian);
$suiteMean = bcdiv($suiteMean, $suiteProfiles, 6);
foreach ($this->profiles as $i => $profiles) {
foreach($profiles['results'] as $j => $stats) {
- $stats['pc'] = (($stats['mean'] / $suiteMedian) * 100) - 100;
+ $stats['pc_suite'] = (($stats['mean'] / $suiteMedian) * 100) - 100;
$this->profiles[$i]['results'][$j] = $stats;
}
}
@@ -144,6 +150,21 @@ protected function getLabel($method) {
}
return false;
}
+
+ protected function getMedian($values) {
+ sort($values);
+ if (count($values) % 2 == 0) {
+ // even, take an average of the middle two
+ $top = count($values) / 2;
+ $bottom = $top - 1;
+
+ $median = bcdiv($values[$bottom] + $values[$top], 2, 6);
+ } else {
+ $idx = floor(count($values) / 2);
+ $median = $values[$idx];
+ }
+ return $median;
+ }
}
$classes = array();
View
@@ -3,6 +3,7 @@
<head>
<title>PHP Performance Metrics</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
+ <meta name="google-site-verification" content="25AfGx-XF6ikgholPhv2GQ5sTxLz0gk13Eklidw3bds" />
<style>
tr.group th {
font-weight:bold;
@@ -37,7 +38,7 @@
</script>
</head>
<body>
- <a href="<?php echo $this->url ?>../../../"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
+ <a href="<?php echo $this->url ?>"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<div class=container>
<div class='page-header'>
<div style='margin-top:11px;float:right'>
@@ -48,7 +49,7 @@
<p>The table below shows methods loosely grouped by type and usage. The column representing a <em>single</em>
method call is derived solely from dividing the mean value by the number of iterations, so it is approximate.
- The relative column shows the cost of the method Vs the <strong>median</strong> across all profiled functions.</p>
+ The relative column shows the cost of the method Vs the <strong>median</strong> across both the group and suite of profiled functions.</p>
<p>You can click on any group's heading to view the profile class as a whole, or you can click on each
individual method to be taken to the source code behind each profile &ndash; particularly useful
@@ -97,28 +98,30 @@
<tbody>
<?php foreach($this->profiles as $profile): ?>
<tr class=group>
- <th><a href='<?php echo $this->url.$profile['filename'] ?>'><?php echo $profile['title'] ?></a></th>
+ <th><a href='<?php echo $this->url.'tree/master/profiles/'.$profile['filename'] ?>'><?php echo $profile['title'] ?></a></th>
<th>&times; <?php echo number_format($this->meta['iterations']) ?></th>
<th>&times; 1</th>
- <th>Relative</th>
+ <th>Rel. (Group)</th>
+ <th>Rel. (Suite)</th>
</tr>
<?php foreach($profile['results'] as $stats): ?>
<tr>
- <td><a href='<?php echo $this->url.$profile['filename'] ?>#L<?php echo $stats['startLine'] ?>'><?php echo $this->highlight($stats['label']) ?></a></td>
+ <td><a href='<?php echo $this->url.'tree/master/profiles/'.$profile['filename'] ?>#L<?php echo $stats['startLine'] ?>'><?php echo $this->highlight($stats['label']) ?></a></td>
<td><?php echo $stats['mean'] ?> s</td>
<td><?php echo $this->microformat($stats['single']) ?></td>
- <td class='<?php echo ($stats['pc'] < 0) ? 'good' : 'bad' ?>'><?php if ($stats['pc'] > 0):?>+<?php endif; ?><?php echo round($stats['pc'], 2) ?> &#37;</td>
+ <td class='<?php echo ($stats['pc_group'] < 0) ? 'good' : 'bad' ?>'><?php if ($stats['pc_group'] > 0):?>+<?php endif; ?><?php echo round($stats['pc_group'], 2) ?> &#37;</td>
+ <td class='<?php echo ($stats['pc_suite'] < 0) ? 'good' : 'bad' ?>'><?php if ($stats['pc_suite'] > 0):?>+<?php endif; ?><?php echo round($stats['pc_suite'], 2) ?> &#37;</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<div class='page-header'>
- <h2>Contributors</h2>
+ <h2>Contributing</h2>
</div>
<p><b>phpperf</b> needs you! There are <em>loads</em> of methods and common use-cases not yet profiled.
- Please see the <a href='<?php echo $this->url ?>../../../#readme'>readme</a> file for how to add your own tests (it's quick &amp; easy!).
+ Please see the <a href='<?php echo $this->url ?>#readme'>readme</a> file for how to add your own profiles (it's quick &amp; easy!).
Every contributor will be listed here in the order they first helped out with the project. Think of the fame!</p>
<ul>
<li><a href="http://twitter.com/makeusabrew">@makeusabrew</a> (author)</li>
@@ -133,7 +136,6 @@
</div>
Made by <a href="http://twitter.com/makeusabrew">@makeusabrew</a>.
Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License v2.0</a>.
-
</footer>
</body>
</html>

0 comments on commit 021814b

Please sign in to comment.