1 = $

Source: Internet
Author: User

Copyright statement: original works can be reproduced. During reprinting, you must mark the original publication, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://blog.csdn.net/mayongzhan-ma yongzhan, myz, mayongzhan

I saw an article on the Internet, that is, when writing a program, we are used to if ($ A = 1 ), in Wordpress, the author of the article "if (1 = $ A)" said that the latter is three times more efficient than the former... some netizens in my comments later said that the latter was intended to avoid logical errors. for example, if two equal signs are written less than one, the latter will report an error because 1 cannot be assigned. the former will not report errors. some people say that the efficiency of the three equal signs is higher than that of the two. I will test the efficiency by using the class in an article I have previously written. <! -- Class file --> <? PHP/*** @ name test. PHP * @ date Thu Jan 03 22:51:06 CST 2008 * @ copyright Ma yongzhan (myz) * @ author ma yongzhan (myz) * @ link http://blog.csdn.net/mayongzhan/ * // *** test a program how long it do * Note: Please loop multiple times when using, otherwise, the effect cannot be seen * @ package * @ version 1.0 */class testtime {private $ begintime = 0; // start time private $ endtime = 0; // end time public function begin () {$ this-> begintime = microtime (true);} public function end () {$ this-> Endtime = microtime (true);} public function keeptime () {return $ this-> endtime-$ this-> begintime; }}$ A = 1; $ testtime1 = new testtime (); $ testtime1-> begin (); For ($ I = 0; $ I <1000000; $ I ++) {if (1 = $ A) {}}$ testtime1-> end (); echo "1 =/$ :". $ testtime1-> keeptime (); $ testtime2 = new testtime (); $ testtime2-> begin (); For ($ I = 0; $ I <1000000; $ I ++) {if ($ A = 1) {}}$ testtime2-> end (); echo "<br/>/$ A = 1: ". $ Testtime2-> keeptime (); $ testtime3 = new testtime (); $ testtime3-> begin (); For ($ I = 0; $ I <1000000; $ I ++) {if ($ A = 1) {}}$ testtime3-> end (); echo "<br/>/$ A = 1: ". $ testtime3-> keeptime (); $ testtime4 = new testtime (); $ testtime4-> begin (); For ($ I = 0; $ I <1000000; $ I ++) {if (1 = $ A) {}}$ testtime4-> end (); echo "<br/> 1 =/$: ". $ testtime4-> keeptime ();?> <! -- Run the result of 1000000 times. It can be seen that the efficiency of the three equal signs is higher than that of the two. The efficiency is the same as that of the first write. 1 = $ A: 0.22159481048584
$ A = 1: 0.22365593910217
$ A = 1: 0.18903613090515
1 ===$ A: 0.18533182144165 -->

 

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.