$statement = function ($json) { return @json_decode($json, false, 512, JSON_BIGINT_AS_STRING); }; } else { $statement = function ($json) { return @json_decode($json); }; } foreach (timeattack('Function-JSON decoding (Array)', 100000) as $_) { $ignore = $statement($json_array); } foreach (timeattack('Json\\Json encoding (Object)', 100000) as $_) { $ignore = \Json\Json::stringify($php_object); } foreach (timeattack('JSON encoding (Array)', 100000) as $_) { $ignore = \Json\Json::stringify($php_array); } foreach (timeattack('Raw-JSON encoding (Object)', 100000) as $_) { $ignore = @json_encode($php_object, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } foreach (timeattack('Raw-JSON encoding (Array)', 100000) as $_) { $ignore = @json_encode($php_array, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } $is_supported = version_compare(PHP_VERSION, '5.4.0', '>='); foreach (timeattack('IfVersioning-JSON encoding (Object)', 100000) as $_) { if ($is_supported) { $ignore = @json_encode($php_object, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } else { $ignore = @json_encode($php_object); } }
timeattack('JSON encoding (Object)', 100000, function () use($object) { // $ignore = json_encode($object); $ignore = \Json\Json::stringify($object); }); timeattack('JSON encoding (Array)', 100000, function () use($array) { // $ignore = json_encode($array); $ignore = \Json\Json::stringify($array); }); timeattack('JSON encoding (Null)', 100000, function () { // $ignore = json_encode(null); $ignore = \Json\Json::stringify(null); }); timeattack('JSON encoding (hasError)', 100000, function () use($fp) { // $ignore = json_encode(array($fp)); try { $ignore = \Json\Json::stringify(array($fp)); } catch (\Json\Exception\Encoding $e) { } }); echo "-------------------------\n"; echo "done.\n"; ob_start(function ($buffer) { return ''; }); ?> 5.5.27 ------------------------- JSON encoding (Object) * 100000: 0.51506591 sec JSON encoding (Array) * 100000: 0.27953506 sec JSON encoding (Null) * 100000: 0.05300689 sec