-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_parser.php
More file actions
67 lines (51 loc) · 1.83 KB
/
test_parser.php
File metadata and controls
67 lines (51 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Padam87\PdfPreflight;
include 'vendor/autoload.php';
use Symfony\Component\Stopwatch\Stopwatch;
// This file is for measuring the Parser against the original TCPDF one
foreach (['./gls.pdf', './js.pdf', './hotel.pdf', './test.pdf', './test2.pdf', './test2b.pdf', './test3.pdf'] as $file) {
$s = new Stopwatch();
$contents = file_get_contents($file);
$s->start('original');
$originalData = (new \TCPDF_PARSER($contents))->getParsedData();
$original = $s->stop('original');
$p = new \Padam87\PdfPreflight\Parser\Parser();
$s->start('optimized');
$optimizedData = $p->parse($contents);
$optimized = $s->stop('optimized');
$s->start('decoded');
$decodedData = $p->parse($contents, false);
$decoded = $s->stop('decoded');
dump(
[
'file' => $file,
'original' => $original->getDuration(),
'optimized' => $optimized->getDuration(),
'not_decoded' => $decoded->getDuration(),
//'diff' => isSame($originalData[1], $optimizedData[1]),
]
);
assert(array_keys($originalData[1]) == array_keys($optimizedData[1]));
}
function isSame($a, $b, $keychain = [], $ta = null, $tb = null)
{
foreach ($a as $k => $va) {
$vb = $b[$k];
$valid = @assert($va == $vb);
if (!$valid) {
$keychain[] = $k;
if (is_array($va) && is_array($vb)) {
return isSame($va, $vb, $keychain, $ta == null ? $va : $ta, $tb == null ? $vb : $tb);
} else {
return [
'keychain' => implode(' .. ', $keychain),
'original' => $va,
'optimized' => $vb,
'topOriginal' => $ta,
'topOptimized' => $tb,
];
}
}
}
return true;
}