当前位置:网站首页>Detailed explanation of PHP data serialization test example

Detailed explanation of PHP data serialization test example

2022-06-24 07:42:00 User 2323866

php Detailed explanation of data serialization test examples Test code

$msg = ['test'=>23]; $start = microtime(true); for($i=0;$i<100000;$i++){ $packMsg = msgpack_pack($msg); } echo 'pack len:'.strlen($packMsg)."rn"; $end = microtime(true); echo 'run time:'.($end-$start).'s'."rn"; echo 'memory usage:'.(memory_get_usage()/1024)."KBrn"; /* $start = microtime(true); for($i=0;$i<100000;$i++){ $jsonMsg = json_encode($msg); } echo 'json len:'.strlen($jsonMsg)."rn"; $end = microtime(true); echo 'run time:'.($end-$start).'s'."rn"; echo 'memory usage:'.(memory_get_usage()/1024)."KBrn";

$start = microtime(t/【php course _linux Common commands _ Network operation and maintenance technology 】/rue); for($i=0;$i<100000;$i++){ $packMsg = serialize($msg); } echo 'php len:'.strlen($packMsg)."rn"; $end = microtime(true); echo 'run time:'.($end-$start)."srn"; echo 'memory usage:'.(memory_get_usage()/1024)."KBrn";*/

Execution results

pack len:7 run time:0.024219989776611s memory usage:354.4765625KB json len:11 run time:0.010890007019043s memory usage:354.1796875KB php len:22 run time:0.010586977005005s memory usage:353.8828125KB

Analyze comments The basic results of online search are ( Estimation is php7 Previous versions )

Running speed serialize<json<msgpack length serialize>json>msgpack Memory consumption serialize<json<msgpack // But almost the same

stay php7 Running in , The results are as follows

Running speed serialize<msgpack<json // There's a change here length serialize>json>msgpack Memory consumption serialize<json<msgpack // But almost the same

That's all php Explanation of data serialization test , If you have any questions, please leave a message or go to our community to exchange and discuss /【 Some of this PHP The version may be a previous one , If it doesn't have to be , Suggest PHP Use as much as possible 7.2 Version above 】/, Thank you for reading , I hope I can help you , Thank you for your support !

原网站

版权声明
本文为[User 2323866]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/06/20210629105137478u.html