Skip to content

Commit 43e28f9

Browse files
committed
Refactor: move a function to a file
1 parent 0d46cc4 commit 43e28f9

File tree

2 files changed

+47
-44
lines changed

2 files changed

+47
-44
lines changed

index.php

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,21 @@
11
<?php
22

3-
require __DIR__ . '/libs/php-recipe-2nd/make_chart_parts.php';
43
require __DIR__ . '/libs/parse_results.php';
4+
require __DIR__ . '/libs/make_graph.php';
55

66
$results = parse_results(__DIR__ . '/output/results.hello_world.log');
77

8-
function makeGraph($id, $title, $hAxis_title)
9-
{
10-
global $results;
11-
12-
$barColors = array(
13-
'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGreen',
14-
'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'DarkOrange', 'DarkOrchid',
15-
'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray',
16-
'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGreen',
17-
'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'DarkOrange', 'DarkOrchid',
18-
'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray',
19-
);
20-
$graphWidth = 1000;
21-
$graphHeight = 400;
22-
23-
$data = array();
24-
$data[] = array('', $id, array('role' => 'style')); // header
25-
26-
$colors = $barColors;
27-
foreach ($results as $fw => $result) {
28-
$data[] = array($fw, $result[$id], array_shift($colors));
29-
}
30-
//var_dump($data); exit;
31-
32-
$options = array(
33-
'title' => $title,
34-
'titleTextStyle' => array('fontSize' => 16),
35-
'hAxis' => array('title' => $hAxis_title,
36-
'titleTextStyle' => array('bold' => true)),
37-
'vAxis' => array('minValue' => 0, 'maxValue' => 0.01),
38-
'width' => $graphWidth,
39-
'height' => $graphHeight,
40-
'bar' => array('groupWidth' => '90%'),
41-
'legend' => array('position' => 'none')
42-
);
43-
$type = 'ColumnChart';
44-
return makeChartParts($data, $options, $type);
45-
}
46-
478
// RPS Benchmark
48-
list($chart_rpm, $div_rpm) = makeGraph('rps', 'Throughput', 'requests per second');
9+
list($chart_rpm, $div_rpm) = make_graph('rps', 'Throughput', 'requests per second');
4910

5011
// Memory Benchmark
51-
list($chart_mem, $div_mem) = makeGraph('memory', 'Memory', 'peak memory (MB)');
12+
list($chart_mem, $div_mem) = make_graph('memory', 'Memory', 'peak memory (MB)');
5213

5314
// Exec Time Benchmark
54-
list($chart_time, $div_time) = makeGraph('time', 'Exec Time', 'ms');
15+
list($chart_time, $div_time) = make_graph('time', 'Exec Time', 'ms');
5516

5617
// Included Files
57-
list($chart_file, $div_file) = makeGraph('file', 'Included Files', 'count');
18+
list($chart_file, $div_file) = make_graph('file', 'Included Files', 'count');
5819
?>
5920
<!DOCTYPE html>
6021
<html lang="en">

libs/make_graph.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
require __DIR__ . '/php-recipe-2nd/make_chart_parts.php';
4+
5+
function make_graph($id, $title, $hAxis_title)
6+
{
7+
global $results;
8+
9+
$barColors = array(
10+
'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGreen',
11+
'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'DarkOrange', 'DarkOrchid',
12+
'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray',
13+
'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGreen',
14+
'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'DarkOrange', 'DarkOrchid',
15+
'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray',
16+
);
17+
$graphWidth = 1000;
18+
$graphHeight = 400;
19+
20+
$data = array();
21+
$data[] = array('', $id, array('role' => 'style')); // header
22+
23+
$colors = $barColors;
24+
foreach ($results as $fw => $result) {
25+
$data[] = array($fw, $result[$id], array_shift($colors));
26+
}
27+
//var_dump($data); exit;
28+
29+
$options = array(
30+
'title' => $title,
31+
'titleTextStyle' => array('fontSize' => 16),
32+
'hAxis' => array('title' => $hAxis_title,
33+
'titleTextStyle' => array('bold' => true)),
34+
'vAxis' => array('minValue' => 0, 'maxValue' => 0.01),
35+
'width' => $graphWidth,
36+
'height' => $graphHeight,
37+
'bar' => array('groupWidth' => '90%'),
38+
'legend' => array('position' => 'none')
39+
);
40+
$type = 'ColumnChart';
41+
return makeChartParts($data, $options, $type);
42+
}

0 commit comments

Comments
 (0)