Skip to content

Instantly share code, notes, and snippets.

@mstaack
Last active April 5, 2017 17:34
Show Gist options
  • Select an option

  • Save mstaack/9f77a98661e8438ef365 to your computer and use it in GitHub Desktop.

Select an option

Save mstaack/9f77a98661e8438ef365 to your computer and use it in GitHub Desktop.
quick n easy benchmark
require_once 'vendor/autoload.php';
$mbox = imap_open('{demo.host.com:993/imap/ssl/novalidate-cert}INBOX', 'demo@host.de', 'megasecurepassword') or die("connection errror: " . imap_last_error());
/**
* @param $imap_body
* @throws Exception
*/
function parse_with_extension($imap_body)
{
$Parser = new PhpMimeMailParser\Parser();
$Parser->setText($imap_body);
// We can get all the stuff easily ;)
$subject = $Parser->getHeader('subject') . PHP_EOL;
$from = $Parser->getHeader('from') . PHP_EOL;
}
function parse_with_native($imap_body)
{
$mailParser = new ZBateson\MailMimeParser\MailMimeParser();
$handle = fopen('data://text/plain,' . $imap_body, 'r');
$message = $mailParser->parse($handle); // returns a ZBateson\MailMimeParser\Message
fclose($handle);
$from = $message->getHeaderValue('from') . PHP_EOL; // user@example.com
$subject = $message->getHeaderValue('subject') . PHP_EOL;
}
$bench = new Ubench;
$bench->start();
for ($jk = 1; $jk <= 30; $jk++) {
$imap_body = imap_fetchheader($mbox, $jk) . imap_body($mbox, $jk);
parse_with_extension($imap_body);
// parse_with_native($imap_body);
}
$bench->end();
echo 'time: ' . $bench->getTime() . PHP_EOL; // 156ms or 1.123s
echo 'memory: ' . $bench->getMemoryUsage(); // 152B or 90.00Kb or 15.23Mb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment