php数据序列化测试实例详解
php数据序列化测试实例详解
测试代码
$msg = ['test'=>23]; $start = microtime(true); for($i=0;$i<100000;$i++){ $packMsg = msgpack_pack($msg); } echo 'pack len:'.strlen($packMsg)."\r\n"; $end = microtime(true); echo 'run time:'.($end-$start).'s'."\r\n"; echo 'memory usage:'.(memory_get_usage()/1024)."KB\r\n"; /* $start = microtime(true); for($i=0;$i<100000;$i++){ $jsonMsg = json_encode($msg); } echo 'json len:'.strlen($jsonMsg)."\r\n"; $end = microtime(true); echo 'run time:'.($end-$start).'s'."\r\n"; echo 'memory usage:'.(memory_get_usage()/1024)."KB\r\n"; $start = microtime(true); for($i=0;$i<100000;$i++){ $packMsg = serialize($msg); } echo 'php len:'.strlen($packMsg)."\r\n"; $end = microtime(true); echo 'run time:'.($end-$start)."s\r\n"; echo 'memory usage:'.(memory_get_usage()/1024)."KB\r\n";*/
执行结果
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
分析评论
网上查阅的基本结果都是(估计是php7以前的版本)
运行速度 serialize<json<msgpack 长度 serialize>json>msgpack 内存消耗 serialize<json<msgpack //不过近乎一致
在php7里运行,得出的结果如下
运行速度 serialize<msgpack<json //这里出现了变化 长度 serialize>json>msgpack 内存消耗 serialize<json<msgpack //不过近乎一致
以上就是php数据序列化测试的讲解,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关推荐
hedongli 2020-09-01
MXstudying 2020-09-05
WasteLand 2020-09-15
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh
mathchao 2020-09-15
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28