Random musings on Life, World, Technology

July 25, 2006

Optimizing PHP

Filed under: Technology — prasoonk @ 10:09 pm

The following tips can help in optimizing object-orientated PHP.

1. Initialise all variables before use.

2. Dereference all global/property variables that are frequently used in a method and put the values in local variables if you plan to access the value more than twice.

3. Try placing frequently used methods in the derived classes.

Warning: as PHP is going through a continuous improvement process, things might change in the future.

More Details

I have found that calling object methods (functions defined in a class) are about twice as slow as a normal function calls. To me that’s quite acceptable and comparable to other OOP languages.

Inside a method (the following ratios are approximate only):

1. Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.
2. Incrementing a global variable is 2 times slow than a local var.
3. Incrementing a object property (eg. $this->prop++) is 3 times slower than a local variable.
4. Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.
5. Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.
6. Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.
7. Methods in derived classes run faster than ones defined in the base class.
8. A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.

July 19, 2006

Mobile Monday Delhi and some recent mobile news

Filed under: Technology — prasoonk @ 11:55 am

Mobile Monday

The word is out:- The mobile Monday event is happenning in Adobe, Noida on the 1st Monday Saturday of August i.e. 5th from 930am till 630pm. Adobe is graciously hosting the event. They have become un-conference world’s best friends in NCR. They had offered their conference rooms, free WiFi in the 1st Barcamp held in India. Uzanto again gets going with a good volunteering, like they did the last time. I am still a parasite of these un-conferences by being the audience and doing networking at such sessions. I am trying to change this by becoming a volunteer this time. I am also trying to spread the word by writing this blog and emailing a couple of friends. so, mobile enthusiasts of Delhi gear up and signup at MoMoDelhi wiki. I will also share some recent developments in the mobile space. Let me start doing that right now.

  • Linux is the rising star of the mobile OS market – reports ITWire.

Some key benefits of Linux as a mobile OS include its small kernel size, open source, and low (no) cost. But, the lack of a single set of standards can be detrimental to its adoption.

Blog at WordPress.com.