This article mainly introduces the PHP data serialization test example of the relevant information, mainly introduces Msgpack, JSON, serialize contrast, the need for friends can refer to the next
PHP Data Serialization Test example detailed
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:7run time:0.024219989776611smemory Usage:354.4765625kbjson len:11run time:0.010890007019043smemory usage : 354.1796875KBphp len:22run time:0.010586977005005smemory usage:353.8828125kb
Analysis Review
The basic results of online access are (estimated to be php7 previous versions)
Operating speed Serialize<json<msgpack length serialize>json>msgpack memory consumption serialize<json<msgpack//But almost consistent
Running in PHP7, the results are as follows
Run speed Serialize<msgpack<json //There is a change in length serialize>json>msgpack memory consumption serialize<json< Msgpack//But almost unanimous