streams/vendor/sabre/vobject/bin/bench_manipulatevcard.php

65 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2019-04-09 01:35:23 +00:00
include __DIR__.'/../vendor/autoload.php';
if ($argc < 2) {
2019-04-09 01:35:23 +00:00
echo 'sabre/vobject ', Sabre\VObject\Version::VERSION, " manipulation benchmark\n";
echo "\n";
echo "This script can be used to measure the speed of opening a large amount of\n";
echo "vcards, making a few alterations and serializing them again.\n";
2019-04-09 01:35:23 +00:00
echo 'system.';
echo "\n";
2019-04-09 01:35:23 +00:00
echo 'Usage: '.$argv[0]." inputfile.vcf\n";
die();
}
list(, $inputFile) = $argv;
$input = file_get_contents($inputFile);
$splitter = new Sabre\VObject\Splitter\VCard($input);
$bench = new Hoa\Bench\Bench();
while (true) {
$bench->parse->start();
$vcard = $splitter->getNext();
$bench->parse->pause();
2019-04-09 01:35:23 +00:00
if (!$vcard) {
break;
}
$bench->manipulate->start();
$vcard->{'X-FOO'} = 'Random new value!';
$emails = [];
2019-04-09 01:35:23 +00:00
if (isset($vcard->EMAIL)) {
foreach ($vcard->EMAIL as $email) {
$emails[] = (string) $email;
}
}
$bench->manipulate->pause();
$bench->serialize->start();
$vcard2 = $vcard->serialize();
$bench->serialize->pause();
$vcard->destroy();
}
echo $bench,"\n";
2019-04-09 01:35:23 +00:00
function formatMemory($input)
{
if (strlen($input) > 6) {
2019-04-09 01:35:23 +00:00
return round($input / (1024 * 1024)).'M';
} elseif (strlen($input) > 3) {
2019-04-09 01:35:23 +00:00
return round($input / 1024).'K';
}
}
unset($input, $splitter);
2019-04-09 01:35:23 +00:00
echo 'peak memory usage: '.formatMemory(memory_get_peak_usage()), "\n";
echo 'current memory usage: '.formatMemory(memory_get_usage()), "\n";