bench.php
7 months ago
bench_freebusygenerator.php
7 months ago
bench_manipulatevcard.php
7 months ago
fetch_windows_zones.php
1 year ago
generate_vcards
1 year ago
generateicalendardata.php
7 months ago
mergeduplicates.php
7 months ago
rrulebench.php
7 months ago
vobject
1 year ago
bench_manipulatevcard.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | include __DIR__ . '/../vendor/autoload.php'; |
| 4 | if ($argc < 2) { |
| 5 | echo 'sabre/vobject ', \AmeliaVendor\Sabre\VObject\Version::VERSION, " manipulation benchmark\n"; |
| 6 | echo "\n"; |
| 7 | echo "This script can be used to measure the speed of opening a large amount of\n"; |
| 8 | echo "vcards, making a few alterations and serializing them again.\n"; |
| 9 | echo 'system.'; |
| 10 | echo "\n"; |
| 11 | echo 'Usage: ' . $argv[0] . " inputfile.vcf\n"; |
| 12 | exit; |
| 13 | } |
| 14 | list(, $inputFile) = $argv; |
| 15 | $input = file_get_contents($inputFile); |
| 16 | $splitter = new \AmeliaVendor\Sabre\VObject\Splitter\VCard($input); |
| 17 | $bench = new Hoa\Bench\Bench(); |
| 18 | while (true) { |
| 19 | $bench->parse->start(); |
| 20 | $vcard = $splitter->getNext(); |
| 21 | $bench->parse->pause(); |
| 22 | if (!$vcard) { |
| 23 | break; |
| 24 | } |
| 25 | $bench->manipulate->start(); |
| 26 | $vcard->{'X-FOO'} = 'Random new value!'; |
| 27 | $emails = []; |
| 28 | if (isset($vcard->EMAIL)) { |
| 29 | foreach ($vcard->EMAIL as $email) { |
| 30 | $emails[] = (string) $email; |
| 31 | } |
| 32 | } |
| 33 | $bench->manipulate->pause(); |
| 34 | $bench->serialize->start(); |
| 35 | $vcard2 = $vcard->serialize(); |
| 36 | $bench->serialize->pause(); |
| 37 | $vcard->destroy(); |
| 38 | } |
| 39 | echo $bench, "\n"; |
| 40 | function formatMemory($input) |
| 41 | { |
| 42 | if (strlen($input) > 6) { |
| 43 | return round($input / (1024 * 1024)) . 'M'; |
| 44 | } elseif (strlen($input) > 3) { |
| 45 | return round($input / 1024) . 'K'; |
| 46 | } |
| 47 | } |
| 48 | unset($input, $splitter); |
| 49 | echo 'peak memory usage: ' . formatMemory(memory_get_peak_usage()), "\n"; |
| 50 | echo 'current memory usage: ' . formatMemory(memory_get_usage()), "\n"; |