Home > Article > Backend Development > Detailed explanation of 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
php data serialization test examples. Detailed explanation
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 and comments
The basic results of online searches are all (presumably versions before php7)
运行速度 serialize<json<msgpack 长度 serialize>json>msgpack 内存消耗 serialize<json<msgpack //不过近乎一致
Run in php7, the results are as follows
运行速度 serialize<msgpack<json //这里出现了变化 长度 serialize>json>msgpack 内存消耗 serialize<json<msgpack //不过近乎一致
Related recommendations:
Use native js to implement form formSerialization (graphic tutorial)
##PHP Serialization and reverseSerializationDetailed explanation of function examples
JSONSerialization and reverseSerializationImplementation method (with code)
The above is the detailed content of Detailed explanation of php data serialization testing. For more information, please follow other related articles on the PHP Chinese website!