Avoid if/ else within loop

Yes, this post is about the most basic concept that using if/ else should be avoided within a loop as much as possible. Optimizing code is always important and when it’s about performance then the basic efficiency rules should be followed at first. Practically there are many situations when a loop iterates over large data set e.g. 10m; there may be differently required computation in the same loop- but if possible the loop should maintain branch prediction; avoid unnecessary if/ else.

Following simple rules lead to performance advantage certainly. Branch prediction is a simple concept to optimize a loop-
Continue reading


RabbitMQ installation

Here, RabbitMQ installation steps are described for Ubuntu, based on the RabbitMQ install guide : http://www.rabbitmq.com/install-debian.html

Basically this should be enough if the additional dependencies are already in

sudo apt-get install rabbitmq-server

But I was having some trouble due to its other required dependencies. Listed them down here, may be useful for others-

Continue reading

What is deep copy and shallow copy? How PHP uses them?

I got this question in an interview. Was aware of this conception and explained properly. But I think this topic is worth to explain, so that’s why this post is-

Shallow copy– In the process of shallow copying A, B will copy all of A’s field values. If the field value is a memory address it copies the memory address, and if the field value is a primitive type it copies the value of the primitive type. In layman’s term, shallow copy duplicates as minimum as possible. But the disadvantage is if you modify the memory address that one of B’s fields point to, you are also modifying what A’s fields point to.

Deep copy– In this process the data is actually copied completely. The advantage is that A and B do not depend on each other but this process is relatively slower and more expensive.
Continue reading