Comparison between PHP static latency binding and common static efficiency, and php static latency binding

Source: Internet
Author: User

Comparison between PHP static latency binding and common static efficiency, and php static latency binding

Comparison between static latency binding in PHP and normal static efficiency

It's just a simple small experiment that compares the latency binding and non-latency efficiency.

Delayed binding mainly uses the static keyword to replace the original self, but the function is very powerful.

Lab code:

class A {   protected static $cc1 = array('a1', 'b', 'c', 'd');   protected static $cc2 = array('a2', 'b', 'c', 'd');   protected static $cc3 = array('a3', 'b', 'c', 'd');   protected static $cc4 = array('a4', 'b', 'c', 'd');   protected static $cc5 = array('a5', 'b', 'c', 'd');    public static function n1() {     return static::$cc1;   }   public static function n2() {     return static::$cc2;   }   public static function n3() {     return static::$cc3;   }   public static function n4() {     return static::$cc4;   }   public static function n5() {     return static::$cc5;   } }  class C extends A {  }  class B {   protected static $cc1 = array('a1', 'b', 'c', 'd');   protected static $cc2 = array('a2', 'b', 'c', 'd');   protected static $cc3 = array('a3', 'b', 'c', 'd');   protected static $cc4 = array('a4', 'b', 'c', 'd');   protected static $cc5 = array('a5', 'b', 'c', 'd');    public static function n1() {     return self::$cc1;   }   public static function n2() {     return self::$cc2;   }   public static function n3() {     return self::$cc3;   }   public static function n4() {     return self::$cc4;   }   public static function n5() {     return self::$cc5;   } } 

The preceding three classes are A, B, and C, which are all static member variables and methods.

Class A uses static latency,
Class B is non-latency,
Class C inherits Class A and implements delayed binding between static member variables and methods.

The process is not mentioned much. The environment is PHP5.4.27 and the test result is directly displayed:

There are two situations,

1. When only Class A and Class B (that is, do not let any class inherit Class A), there is almost no difference in efficiency.

2. When Class A is inherited by Class C, the performance of Class A bound with static latency will be slightly worse than that of Class B (as long as class A has inherited classes, it will be slower)

The number of cycles is 100,000, which takes 2.8 seconds ~ The time difference between 3.2 s is about 0.3 seconds. It should be negligible.

Additional information:Later I added some test methods. If Class C inherits Class A and some static member variables in Class A are reloaded, the more I reload, the higher the speed and class B (non-delay) the closer it is, the slower the speed of Class A than that of class B and class C.

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

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.