Beispiel #1
0
        for ($i = 0; $i < $repeat; $i++) {
            yield;
        }
    }
}
$php_object = array('name' => 'Luke Skywalker', 'teacher' => 'Yoda', 'job' => 'Jedi', 'force' => true, 'height' => 1.72, 'weight' => 77, 'droid' => array('C-3PO', 'R2-D2'));
$php_array = array(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
$json_object = '{"name":"Luke Skywalker","teacher":"Yoda","job":"Jedi","force":true,"height":1.72,"weight":77,"droid":["C-3PO","R2-D2"]}';
$json_array = '[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]';
echo PHP_VERSION . "\n";
echo "-------------------------\n";
foreach (timeattack('Json\\Json decoding (Object)', 100000) as $_) {
    $ignore = \Json\Json::parse($json_object);
}
foreach (timeattack('Json\\Json decoding (Array)', 100000) as $_) {
    $ignore = \Json\Json::parse($json_array);
}
foreach (timeattack('Raw-JSON decoding (Object)', 100000) as $_) {
    $ignore = @json_decode($json_object, false, 512, JSON_BIGINT_AS_STRING);
}
foreach (timeattack('Raw-JSON decoding (Array)', 100000) as $_) {
    $ignore = @json_decode($json_array, false, 512, JSON_BIGINT_AS_STRING);
}
$is_supported = version_compare(PHP_VERSION, '5.4.0', '>=');
foreach (timeattack('IfVersioning-JSON decoding (Object)', 100000) as $_) {
    if ($is_supported) {
        $ignore = @json_decode($json_object, false, 512, JSON_BIGINT_AS_STRING);
    } else {
        $ignore = @json_decode($json_object);
    }
}
Beispiel #2
0
}
$object = '{"name":"Luke Skywalker","teacher":"Yoda","job":"Jedi","force":true,"height":1.72,"weight":77,"droid":["C-3PO","R2-D2"]}';
$array = '[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]';
echo PHP_VERSION . "\n";
echo "-------------------------\n";
timeattack('JSON decoding (Object)', 100000, function () use($object) {
    // $ignore = json_decode($object);
    $ignore = \Json\Json::parse($object);
});
timeattack('JSON decoding (Array)', 100000, function () use($array) {
    // $ignore = json_decode($array);
    $ignore = \Json\Json::parse($array);
});
timeattack('JSON decoding (Null)', 100000, function () {
    // $ignore = json_decode('');
    $ignore = \Json\Json::parse('');
});
echo "-------------------------\n";
echo "done.\n";
ob_start(function ($buffer) {
    return '';
});
?>

5.5.27
-------------------------
JSON decoding (Object) * 100000: 0.96562314 sec
JSON decoding (Array) * 100000: 0.78059888 sec
JSON decoding (Null) * 100000: 0.09851217 sec

5.5.27