示例#1
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     $parser = null;
     // php extension
     if (class_exists('\\HStoreCppParser')) {
         $parser = new \HStoreCppParser();
     } elseif (class_exists('\\HStore\\HStoreParser')) {
         $parser = new \HStore\HStoreParser();
     } else {
         $parser = new \Intaro\HStoreBundle\HStore\HStoreParser();
     }
     try {
         $value = $parser->parse($value);
     } catch (\Exception $e) {
         throw ConversionException::conversionFailed($e->getMessage(), $this->getName());
     }
     return $value;
 }
<?php

require __DIR__ . '/../../HStore/Exception/ConversionException.php';
require __DIR__ . '/../../HStore/HStoreParser.php';
$examples = (require __DIR__ . '/../Resources/strings.php');
function show_report($type, $time, $counter, $mpu, $mu)
{
    echo $type . ": " . $time * 1000 . " ms for {$counter} strings\n";
    echo "Memory peak usage: " . $mpu / 1024 / 1024 . " MB\n";
    echo "Memory usage: " . $mu / 1024 / 1024 . " MB\n";
    echo "\n";
}
$parser1 = new Intaro\HStoreBundle\HStore\HStoreParser();
$parser2 = new HStore\HStoreParser();
$parser3 = new HStoreCppParser();
//////////////////////////////////////////////////
echo "Checking execution:\n";
for ($i = 0, $n = sizeof($examples); $i < $n; $i++) {
    $str1 = $parser1->parse($examples[$i]);
    $str2 = $parser2->parse($examples[$i]);
    $str3 = $parser2->parse($examples[$i]);
    echo $str1 === $str2 ? '+' : '-';
    echo $str1 === $str3 ? '+' : '-';
    echo "\n";
}
echo "\n";
//////////////////////////////////////////////////
$t = microtime(true);
$counter = 0;
for ($j = 0; $j < 10; $j++) {
    for ($i = 0, $n = sizeof($examples); $i < $n; $i++) {