Introduction to a serialized instance of PHP data

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.