Archive for the ‘performance’ tag
What’s The Mismatch Between What Science Knows And What Businesses Do?
Fascinating talk by Dan Pink on the surprising science of motivation at TED.
Watch it -
Efforts Vs Results
I think we often confuse efforts and results. Efforts and results are not always proportional. It’s a different story that we expect they should, but in reality, they are not. Why we confuse them?
When we confuse them, we tend to recognize efforts, and reward results. Instead it should be other way around. We should respect and reward people who are putting efforts, and recognize results if those efforts turn into good results.
We need to understand that results are not always guaranteed. They not only depend on amount of efforts put, but also on many other things, which are most of the times not under control of a person putting efforts. Irrespective of the amount of efforts put, results can go wrong because of bad decisions, bad ideas, bad timing, bad market, or bad luck!
Once again, don’t confuse the efforts and results. Reward efforts and recognize results. Not other way around.
The PHP Benchmark
I just stumbled upon a website called PHP Benchmark. It’s a great resource to learn PHP tips for improving performance and speed. These are not advanced tips, but rather very simple tips that we generally don’t pay attention to in our day-to-day programming.
Here is one example -
Is it worth the effort to calculate the length of the loop in advance?
E.g. Should we use
for ($i = 0; $i < $size; $i++)
instead of
for ($i = 0; $i < sizeof($arr); $i++)
The performance result for a loop with 1000 keys with 1 byte values is as below -
With pre calc – count(): Total time: 229 µs
Without pre calc – count(): Total time: 99702 µs
With pre calc – sizeof(): Total time: 235 µs
Without pre calc – sizeof(): Total time: 99610 µs
So it’s very clear that calculating the length of array in advance is way faster than calculating it in the loop.
I hope you’ll find other tips from PHP Benchmark website very useful too.