0

I am currently working on a field level ACL function that will be under really heavy use.

Each data field has to pass through this function before being rendered.

Performance is thus a key issue for this function

  • Does it matter weather I use 1 vs true or 0 vs false?

    ( I know these are not 100% equivalent, I just want to know the performance implications )

  • Would I gain any performance by changing variable name verbosity?

  • Does shorthands like ?:; instead of if else have any impact?

    if($x){ $x; } else { $y; }  VS  $x?$x:$y;
    

Normally I try to keep my code as readable as possible but this is an abnormal case.

I want to squeeze every possible millisecond of performance out of this function.

In addition, any links to pages that compare performance of similar PHP functions would be greatly appreciated.

4

2 回答 2

2

我怀疑 1 vs true 和 0 vs false 有任何明显的性能影响,但如果你想确定你应该创建一个基准。

变量名称长度不应该有任何区别。编译器在解析脚本时将它们全部转换为内部指针。

速记符号也不应该有太大的区别,编译器应该为两者生成类似的代码。

您的担忧似乎都是基于代码被逐行解释的假设。PHP 是编译的,而不是解释的。

于 2013-07-24T14:05:14.653 回答
0

这些问题都不会影响性能。

您正在寻找改善性能的严重错误方法。

于 2013-07-24T14:07:47.977 回答