Skip to content

Commit 438f932

Browse files
committed
Merge branch 'master' of github.com:hexydec/htmldoc
2 parents 1556b64 + 7bb46c3 commit 438f932

File tree

2 files changed

+74
-74
lines changed

2 files changed

+74
-74
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A tokeniser based HTML document parser and minifier, written in PHP.
1111

1212
An HTML parser, primarily designed for minifying HTML documents, it also enables the document structure to be queried allowing attribute and textnode values to be extracted.
1313

14-
Both parsers are designed around a tokeniser to make the document processing more reliable than regex based minifiers, which are a bit blunt and can be problematic if they match patterns in the wrong places.
14+
The parser is designed around a tokeniser to make the document processing more reliable than regex based minifiers, which are a bit blunt and can be problematic if they match patterns in the wrong places.
1515

1616
The software is also capable of processing and minifying SVG documents.
1717

tests/performance.php

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
2-
ini_set('memory_limit', '256M');
3-
$file = dirname(__DIR__).'/vendor/autoload.php';
4-
require(file_exists($file) ? $file : dirname(__DIR__).'/src/autoload.php');
2+
\ini_set('memory_limit', '256M');
3+
$file = \dirname(__DIR__).'/vendor/autoload.php';
4+
require (\file_exists($file) ? $file : \dirname(__DIR__).'/src/autoload.php');
55

66
function fetch($url) {
7-
$cache = __DIR__.'/cache/'.preg_replace('/[^0-9a-z]++/i', '-', $url).'.cache';
7+
$cache = __DIR__.'/cache/'.\preg_replace('/[^0-9a-z]++/i', '-', $url).'.cache';
88
if (file_exists($cache)) {
99
$url = $cache;
1010
}
11-
$context = stream_context_create([
11+
$context = \stream_context_create([
1212
'http' => [
1313
'headers' => [
1414
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
@@ -18,13 +18,13 @@ function fetch($url) {
1818
]
1919
]
2020
]);
21-
$html = file_get_contents($url, false, $context);
21+
$html = \file_get_contents($url, false, $context);
2222
if ($url != $cache) {
23-
$dir = dirname($cache);
24-
if (!is_dir($dir)) {
25-
mkdir($dir, 0755, true);
23+
$dir = \dirname($cache);
24+
if (!\is_dir($dir)) {
25+
\mkdir($dir, 0755, true);
2626
}
27-
file_put_contents($cache, $html);
27+
\file_put_contents($cache, $html);
2828
}
2929
return $html ? $html : false;
3030
}
@@ -58,43 +58,43 @@ function fetch($url) {
5858

5959
// test the performance
6060
foreach ($urls AS $item) {
61-
set_time_limit(30);
62-
$start = microtime(true);
61+
\set_time_limit(30);
62+
$start = \microtime(true);
6363
if (($input = fetch($item)) !== false) {
6464

6565
// Setup the environment
66-
$_SERVER['HTTP_HOST'] = parse_url($item, PHP_URL_HOST);
67-
$_SERVER['REQUEST_URI'] = parse_url($item, PHP_URL_PATH);
68-
$_SERVER['HTTPS'] = mb_strpos($item, 'https://') === 0 ? 'on' : '';
66+
$_SERVER['HTTP_HOST'] = \parse_url($item, PHP_URL_HOST);
67+
$_SERVER['REQUEST_URI'] = \parse_url($item, PHP_URL_PATH);
68+
$_SERVER['HTTPS'] = \mb_strpos($item, 'https://') === 0 ? 'on' : '';
6969

7070
// setup timing
71-
$fetch = microtime(true);
71+
$fetch = \microtime(true);
7272
$results[$item] = [
7373
'load' => $fetch - $start
7474
];
7575

7676
// create the object
7777
$obj = new \hexydec\html\htmldoc($config);
7878
if ($obj->load($input)) {
79-
$load = microtime(true);
79+
$load = \microtime(true);
8080
$results[$item]['parse'] = $load - $fetch;
8181

8282
// minify
8383
$obj->minify();
84-
$minify = microtime(true);
84+
$minify = \microtime(true);
8585
$results[$item]['minify'] = $minify - $load;
8686

8787
// output
8888
$output = $obj->html();
89-
$save = microtime(true);
89+
$save = \microtime(true);
9090

9191
// compile timings
9292
$results[$item]['compile'] = $save - $minify;
9393
$results[$item]['total'] = $save - $fetch;
94-
$results[$item]['input'] = strlen($input);
95-
$results[$item]['inputgz'] = strlen(gzencode($input));
96-
$results[$item]['output'] = strlen($output);
97-
$results[$item]['outputgz'] = strlen(gzencode($output));
94+
$results[$item]['input'] = \strlen($input);
95+
$results[$item]['inputgz'] = \strlen(\gzencode($input));
96+
$results[$item]['output'] = \strlen($output);
97+
$results[$item]['outputgz'] = \strlen(\gzencode($output));
9898
}
9999
} else {
100100
unset($results[$item]);
@@ -156,47 +156,47 @@ function fetch($url) {
156156
foreach ($results AS $key => $item) { ?>
157157
<tr>
158158
<td><?= $i++; ?></td>
159-
<td><h3><a href="<?= htmlspecialchars($key); ?>" target="_blank"><?= htmlspecialchars($key); ?></td>
160-
<td><?= htmlspecialchars(number_format($item['input'])); ?></td>
161-
<td><?= htmlspecialchars(number_format($item['output'])); ?></td>
162-
<td><?= htmlspecialchars(number_format($item['input'] - $item['output'])); ?></td>
163-
<td><?= htmlspecialchars(number_format((100 / $item['input']) * $item['output'], 2)); ?>%</td>
164-
<td><?= htmlspecialchars(number_format($item['inputgz'])); ?></td>
165-
<td><?= htmlspecialchars(number_format($item['outputgz'])); ?></td>
166-
<td><?= htmlspecialchars(number_format($item['inputgz'] - $item['outputgz'])); ?></td>
167-
<td><?= htmlspecialchars(number_format((100 / $item['inputgz']) * $item['outputgz'], 2)); ?>%</td>
168-
<td><?= htmlspecialchars(number_format($item['load'], 4)); ?>s</td>
169-
<td><?= htmlspecialchars(number_format($item['parse'], 4)); ?>s</td>
170-
<td><?= htmlspecialchars(number_format($item['minify'], 4)); ?>s</td>
171-
<td><?= htmlspecialchars(number_format($item['compile'], 4)); ?>s</td>
172-
<td><?= htmlspecialchars(number_format($item['total'], 4)); ?>s</td>
159+
<td><h3><a href="<?= \htmlspecialchars($key); ?>" target="_blank"><?= \htmlspecialchars($key); ?></td>
160+
<td><?= \htmlspecialchars(\number_format($item['input'])); ?></td>
161+
<td><?= \htmlspecialchars(\number_format($item['output'])); ?></td>
162+
<td><?= \htmlspecialchars(\number_format($item['input'] - $item['output'])); ?></td>
163+
<td><?= \htmlspecialchars(\number_format((100 / $item['input']) * $item['output'], 2)); ?>%</td>
164+
<td><?= \htmlspecialchars(\number_format($item['inputgz'])); ?></td>
165+
<td><?= \htmlspecialchars(\number_format($item['outputgz'])); ?></td>
166+
<td><?= \htmlspecialchars(\number_format($item['inputgz'] - $item['outputgz'])); ?></td>
167+
<td><?= \htmlspecialchars(\number_format((100 / $item['inputgz']) * $item['outputgz'], 2)); ?>%</td>
168+
<td><?= \htmlspecialchars(\number_format($item['load'], 4)); ?>s</td>
169+
<td><?= \htmlspecialchars(\number_format($item['parse'], 4)); ?>s</td>
170+
<td><?= \htmlspecialchars(\number_format($item['minify'], 4)); ?>s</td>
171+
<td><?= \htmlspecialchars(\number_format($item['compile'], 4)); ?>s</td>
172+
<td><?= \htmlspecialchars(\number_format($item['total'], 4)); ?>s</td>
173173
</tr>
174174
<?php }
175-
$count = count($results);
176-
$input = array_sum(array_column($results, 'input'));
177-
$output = array_sum(array_column($results, 'output'));
178-
$inputgz = array_sum(array_column($results, 'inputgz'));
179-
$outputgz = array_sum(array_column($results, 'outputgz'));
180-
$load = array_sum(array_column($results, 'load'));
181-
$parse = array_sum(array_column($results, 'parse'));
182-
$minify = array_sum(array_column($results, 'minify'));
183-
$compile = array_sum(array_column($results, 'compile'));
184-
$total = array_sum(array_column($results, 'total')); ?>
175+
$count = \count($results);
176+
$input = \array_sum(\array_column($results, 'input'));
177+
$output = \array_sum(\array_column($results, 'output'));
178+
$inputgz = \array_sum(\array_column($results, 'inputgz'));
179+
$outputgz = \array_sum(\array_column($results, 'outputgz'));
180+
$load = \array_sum(\array_column($results, 'load'));
181+
$parse = \array_sum(\array_column($results, 'parse'));
182+
$minify = \array_sum(\array_column($results, 'minify'));
183+
$compile = \array_sum(\array_column($results, 'compile'));
184+
$total = \array_sum(\array_column($results, 'total')); ?>
185185
<tr style="font-weight:bold">
186186
<td colspan="2">Total</td>
187-
<td><?= htmlspecialchars(number_format($input)); ?></td>
188-
<td><?= htmlspecialchars(number_format($output)); ?></td>
189-
<td><?= htmlspecialchars(number_format($input - $output)); ?></td>
190-
<td><?= htmlspecialchars(number_format((100 / $input) * $output, 2)); ?>%</td>
191-
<td><?= htmlspecialchars(number_format($inputgz)); ?></td>
192-
<td><?= htmlspecialchars(number_format($outputgz)); ?></td>
193-
<td><?= htmlspecialchars(number_format($inputgz - $outputgz)); ?></td>
194-
<td><?= htmlspecialchars(number_format((100 / $inputgz) * $outputgz, 2)); ?>%</td>
195-
<td><?= htmlspecialchars(number_format($load, 4)); ?>s</td>
196-
<td><?= htmlspecialchars(number_format($parse, 4)); ?>s</td>
197-
<td><?= htmlspecialchars(number_format($minify, 4)); ?>s</td>
198-
<td><?= htmlspecialchars(number_format($compile, 4)); ?>s</td>
199-
<td><?= htmlspecialchars(number_format($total, 4)); ?>s</td>
187+
<td><?= \htmlspecialchars(\number_format($input)); ?></td>
188+
<td><?= \htmlspecialchars(\number_format($output)); ?></td>
189+
<td><?= \htmlspecialchars(\number_format($input - $output)); ?></td>
190+
<td><?= \htmlspecialchars(\number_format((100 / $input) * $output, 2)); ?>%</td>
191+
<td><?= \htmlspecialchars(\number_format($inputgz)); ?></td>
192+
<td><?= \htmlspecialchars(\number_format($outputgz)); ?></td>
193+
<td><?= \htmlspecialchars(\number_format($inputgz - $outputgz)); ?></td>
194+
<td><?= \htmlspecialchars(\number_format((100 / $inputgz) * $outputgz, 2)); ?>%</td>
195+
<td><?= \htmlspecialchars(\number_format($load, 4)); ?>s</td>
196+
<td><?= \htmlspecialchars(\number_format($parse, 4)); ?>s</td>
197+
<td><?= \htmlspecialchars(\number_format($minify, 4)); ?>s</td>
198+
<td><?= \htmlspecialchars(\number_format($compile, 4)); ?>s</td>
199+
<td><?= \htmlspecialchars(\number_format($total, 4)); ?>s</td>
200200
</tr>
201201
<?php
202202
$count = count($results);
@@ -212,19 +212,19 @@ function fetch($url) {
212212
?>
213213
<tr style="font-weight:bold">
214214
<td colspan="2">Average</td>
215-
<td><?= htmlspecialchars(number_format($input)); ?></td>
216-
<td><?= htmlspecialchars(number_format($output)); ?></td>
217-
<td><?= htmlspecialchars(number_format($input - $output)); ?></td>
218-
<td><?= htmlspecialchars(number_format((100 / $input) * $output, 2)); ?>%</td>
219-
<td><?= htmlspecialchars(number_format($inputgz)); ?></td>
220-
<td><?= htmlspecialchars(number_format($outputgz)); ?></td>
221-
<td><?= htmlspecialchars(number_format($inputgz - $outputgz)); ?></td>
222-
<td><?= htmlspecialchars(number_format((100 / $inputgz) * $outputgz, 2)); ?>%</td>
223-
<td><?= htmlspecialchars(number_format($load, 4)); ?>s</td>
224-
<td><?= htmlspecialchars(number_format($parse, 4)); ?>s</td>
225-
<td><?= htmlspecialchars(number_format($minify, 4)); ?>s</td>
226-
<td><?= htmlspecialchars(number_format($compile, 4)); ?>s</td>
227-
<td><?= htmlspecialchars(number_format($total, 4)); ?>s</td>
215+
<td><?= \htmlspecialchars(\number_format($input)); ?></td>
216+
<td><?= \htmlspecialchars(\number_format($output)); ?></td>
217+
<td><?= \htmlspecialchars(\number_format($input - $output)); ?></td>
218+
<td><?= \htmlspecialchars(\number_format((100 / $input) * $output, 2)); ?>%</td>
219+
<td><?= \htmlspecialchars(\number_format($inputgz)); ?></td>
220+
<td><?= \htmlspecialchars(\number_format($outputgz)); ?></td>
221+
<td><?= \htmlspecialchars(\number_format($inputgz - $outputgz)); ?></td>
222+
<td><?= \htmlspecialchars(\number_format((100 / $inputgz) * $outputgz, 2)); ?>%</td>
223+
<td><?= \htmlspecialchars(\number_format($load, 4)); ?>s</td>
224+
<td><?= \htmlspecialchars(\number_format($parse, 4)); ?>s</td>
225+
<td><?= \htmlspecialchars(\number_format($minify, 4)); ?>s</td>
226+
<td><?= \htmlspecialchars(\number_format($compile, 4)); ?>s</td>
227+
<td><?= \htmlspecialchars(\number_format($total, 4)); ?>s</td>
228228
</tr>
229229
</tbody>
230230
</table>

0 commit comments

Comments
 (0)