PHP Best Practices: Micro Optimisation (3/11)

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

If you decide to use for instead foreach loop consider replacing count($array) in loop.  Count function is called every single step in loop so for better performance you should declare variable $counter = count($array) just before loop execution.

RiggsPL
Автор

You don't have to do the benchmarks. phpbench (com) has already done that for you. Sure, the differences are small, and neglectible in a small application, but for huge projects it can make that tiny difference.

mamorunl
Автор

I came here hoping to gain knowledge, instead I was presented with a 2+ minutes video telling me to do whatever I like. Please provide useful information, metrics, add URL to extra information, PHP bechmarks (like PHPBench as suggested by Bartosz).

encodedlife
Автор

I usually use single quotes under the assumption that if the content is static, tell the machine it is static.  Otherwise I assume it will be looking for potential variables within it unnecessarily (again, just an assumption). Also, it makes html output easier as i don't need to escape double quotes within it. - if thats lazy and i should escape that, can someone please advise why?

mechanismtrance
Автор

Can u tell me why do You use {} near variable? what it gives? 

Kvvlr
Автор

Are you aware of the range() function?

kalekip
Автор

LOL I hear it always the other way around: one should avoid double quotes and should use single quotes because of performance reasons.

IWasHereFirst
Автор

Sum wasted time other many executions. Yes if you are developing something for a small number of users do what you like, but if it is something on a large scale the sum of the effects will be apparent. Even if it does not effect the users load time enough to say effect a sale on a web store, it may still lead to more cpu time being used. More cpu time being used could directly hurt financially when using a service such as AWS where the time is paid for on tariff or if hosted on a traditional dedicated machine where less costumers can be served by one machine.

morgohill