Home > Article > Backend Development > About php data serialization testing
This article mainly introduces relevant information about the detailed explanation of PHP data serialization test examples. It mainly introduces the comparison of msgpack, json, and serialize. Friends in need can refer to it. I hope it can help everyone.
Detailed explanation of php data serialization test example
Test code
$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";*/
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
Analysis comments
The basic results found online are (estimated to be Versions before php7)运行速度 serialize<json<msgpack 长度 serialize>json>msgpack 内存消耗 serialize<json<msgpack //不过近乎一致is run in php7, and the results are as follows
##
运行速度 serialize<msgpack<json //这里出现了变化 长度 serialize>json>msgpack 内存消耗 serialize<json<msgpack //不过近乎一致
The above is the detailed content of About php data serialization testing. For more information, please follow other related articles on the PHP Chinese website!