PHP Language performance optimization-less use of magic method

Source: Internet
Author: User

Compare the following using the Magic method and the Not applicable magic method run time

Using the Magic method test1.php:

<?PHP/** * Test class*/classtest{Private $name= "Jepeng";  Public function__get ($varname)    {        return $this-name; }}$i= 0; while($i<= 10000) {    $i++; $test=Newtest (); $test-name;}

Do not use magic method test2.php

<?PHP/** * Test class*/classtest{ Public $name= "Jepeng";}$i= 0; while($i<= 100000) {    $i++; $test=Newtest (); $test-name;}

Detection

 time PHP test1. PHP  time PHP test2.php

Results

Test1. phpreal    0m0. 015suser    0m0. 008ssys    0m0. 006stest2. phpreal    0m0. 017suser    0m0. 014ssys    0m0. 002s

Obviously not using magic method of running time is half the Magic method, if the project is large, then the performance impact will be very large.

PHP Language performance optimization-less use of magic method

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.