Repository navigation
Expand file tree
/
Copy pathbenchmark.php
More file actions
76 lines (65 loc) · 2.06 KB
/
Copy pathbenchmark.php
File metadata and controls
76 lines (65 loc) · 2.06 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
67
68
69
70
71
72
73
74
75
76
<?php
/**
* @author Halil Özgür | halil · ozgur |o| gmail.com
*
* Usage: php benchmark.php <FILE_URI/PATH> <DELIMITER_TAG> <METHOD>, e.g.:
* php benchmark.php example.xml product 1
* php benchmark.php http://www.example.com/example.xml product 2
*/
$urlPrefix = "";
/**
* Enable filter
*
* @link http://stackoverflow.com/a/3466609/372654
*/
/*stream_filter_register('xmlutf8', 'ValidUTF8XMLFilter');
class ValidUTF8XMLFilter extends php_user_filter
{
protected static $pattern = '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u';
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = preg_replace(self::$pattern, '', $bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
$urlPrefix = "php://filter/read=xmlutf8/resource=";*/
$url = $urlPrefix . $argv[1];
$elemTagName = $argv[2];
$startTime = microtime(true);
$ct = 0;
$method = "";
switch ($argv[3]) {
case 1:
// V1
$method = "XmlIterator\\XmlIterator";
require_once "XmlIterator/XmlIterator.php";
$it = new XmlIterator\XmlIterator($url, $elemTagName);
foreach ($it as $k => $v) {
$ct++;
// echo $k . " => " . var_export($v, true) . "\n\n";
}
break;
case 2:
// V2 the memory aggressor
$method = "SPL SimpleXMLIterator";
$it = new SimpleXMLIterator($url, null, true);
foreach ($it->{$elemTagName} as $v) {
$ct++;
// echo var_export($v, true) . "\n\n";
// echo (string)$v->element_1 . "\n\n";
}
break;
default:
break;
}
$time = microtime(true) - $startTime;
echo "\n";
echo "method : $method\n";
echo "elem count : $ct\n";
echo "time passed : $time s\n";
// Useless since the memory used by libxml libraries is not reported
//echo "peak memory : " . (memory_get_peak_usage(true) / pow(2, 20)) . " MiB\n";