A simple test of memory occupied by Array and MySQL result sets in PHP scripts

Source: Internet
Author: User

PhpWhen the script is running, the data is stored in the memory,ArrayAndMysqlThe result set is a common data type. The memory usage of the two data types is tested. 

Research and useMemory_get_usage (true)View memory usage

ForArrayType,KeyAndValueWhen all are integers, the size is1 MArray, memory usage is about136 M, Average per record136Bytes.

ForArrayType,KeyIs an integer,ValueIs the length128String, the size is1 MArray, memory usage is about288 M, Average per record288Bytes. 

KeyType

ValueType

Array size

Memory usage

Average

Int

Int

1 M

136 M

136

Int

String (4)

1 M

168 M

168

Int

String (128)

1 M

288 M

288

String (16)

Int

1 M

152 M

152

 

 

 

 

 

 

From the test above, adding a record to the array requires additional data storageAbout100BytesTo maintainHashTable information.(ZvalStorage integer approx.9Bytes?) 

It is worth noting that,MysqlThe result set cannot be stored throughMemory_get_usageThe function is not counted.PhpMemory limit of the script. Pay attention to this feature when writing scripts for reading big data.

Data volume,MyIsamMedium. MYDThe file size is1.2 GBThe sum of all result sets exceeds4G.

Related Article

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.