PHP Data Performance Quiz

Source: Internet
Author: User
Tags array definition
Today, I saw a colleague writing PHP program suddenly want to test the two types of PHP array definition of performance differences


The simple test code is as follows:

1. Use the array keyword

 
  0, ' b ' and ' = 1, ' c ' = 2, ' d ' + 3, ' E ' + 4, ' F ' + 5, ' g ' = 6, ' h ' = 7, ' i ' = 8, ' j ' and 9, ' K ' and 10 , ' l ' +-one, ' m ' = +, ' n ' = +, ' o ' = +, ' p ' = +, ' q ' = +, ' r ' = +, ' s ' = ', ' t ' = ' u ' = +, ' V ' = +, ' w ' = +, ' x ' = +, ' y ', ' + ', ' z ', ' + ', ' A1 ' + 0, ' B1 ' + 1, ' C1 ' + 2, ' D1 ' => ; 3, ' E1 ' and 4, ' F1 ' and 5, ' G1 ' and 6, ' H1 ' + 7, ' i1 ' + 8, ' j1 ' = 9, ' k1 ' and ' = ', ' l1 ' and ' = ', ' M1 ' and 12,  ' N1 ' +, ' o1 ' = +, ' p1 ', ' Q1 ', ' + ', ' R1 ' + +, ' s1 ' + +, ' T1 ' +, ' U1 ', ' v1 ' = ' W1 ' and ' x1 ', ' y1 ', ' Z1 ' and ' 25 ';} Echo '
'; echo time (); exit ();

Execution time: 1398407484-1398407432 = 52s

2. Do not use the array keyword

 '; echo time (); exit ();

Execution Time 1398407870-1398407832 = 38s


They have a huge performance correlation.

So it's best to use a single-row definition when defining an array although this can be a good way to write more code, but some of the higher performance is nice, especially on the most visited sites, especially if you're a C-born programmer.

  • 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.