Skip to content

Commit

Permalink
Add comparison between last two results on table
Browse files Browse the repository at this point in the history
  • Loading branch information
myaaghubi committed Aug 11, 2023
1 parent a0486a5 commit b3866c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ done
if [ "$init_benchmark" = true ]; then
sh ./base/hello_world.sh
echo ''
php ./libs/show_results_table.php
bash results.sh
fi
34 changes: 25 additions & 9 deletions libs/build_table.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

function build_table($results, $header = true)
function build_table($res1, $res2 = null, $header = true)
{
$table = '';

Expand All @@ -9,25 +9,41 @@ function build_table($results, $header = true)
$table .= '|-------------------|------------------------:|-------------:|----------:|-------------:|' . "\n";
}

if (!$results) {
if (!$res1) {
$text = 'Table is empty!';
$lLen = 87;
$lELen = ($lLen - strlen($text))/2;
$table .= sprintf("|%".$lELen."s%".strlen($text)."s%".$lELen."s|\n", '', $text, '');
$lELen = ($lLen - strlen($text)) / 2;

$table .= sprintf("|%" . $lELen . "s%" . strlen($text) . "s%" . $lELen . "s|\n", '', $text, '');
return $table;
}

foreach ($results as $fw => $result) {

foreach ($res1 as $fw => $result) {
$comp['rps'] = '(-)';
$comp['memory'] = '(-)';
if (!empty($res2[$fw])) {
$comp['rps'] = '(' . culc_percentage($result['rps'], $res2[$fw]['rps']) . '%)';
$comp['memory'] = '(' . culc_percentage($result['memory'], $res2[$fw]['memory']) . '%)';
}

$table .= sprintf(
"|%-19s|%25s|%14s|%11s|%14s|\n",
$fw,
number_format($result['rps'], 2),
number_format($result['rps'], 2) . ' ' . @$comp['rps'],
number_format($result['rps_relative'], 1),
number_format($result['memory'], 2),
number_format($result['memory'], 2) . ' ' . @$comp['memory'],
number_format($result['memory_relative'], 1)
);
}

return $table;
}

function culc_percentage($targetNumber, $baseNumber)
{
$diff = $targetNumber - $baseNumber;
$percentage = ($diff / $baseNumber) * 100;
if ($percentage==0)
return 0;
return number_format($percentage, 1);
}
15 changes: 10 additions & 5 deletions libs/show_results_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
rsort($results);

$index = 0;
if (!empty($argv[1]) && $argv[1]<count($results)) {
$index = $argv[1];
if (!empty($argv[1]) && $argv[1] < count($results)) {
$index = intval($argv[1]);
}

if (preg_match("/output\/(\S+)/", @$results[$index], $match)) {
echo "Results: ".@$match[1].PHP_EOL;
echo "Results: " . @$match[1] . PHP_EOL;
}

$pr = parse_results(@$results[$index].'/results.log');
$pr = parse_results(@$results[$index] . '/results.log');

echo build_table($pr);
if ($index + 1 >= count($results)) {
echo build_table($pr);
} else {
$prComp = parse_results(@$results[$index+1] . '/results.log');
echo build_table($pr, $prComp);
}

0 comments on commit b3866c2

Please sign in to comment.