質問

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.

役に立ちましたか?

解決

I doubt that 1 vs true and 0 vs false has any appreciable performance impact, but if you want to know for sure you should create a benchmark.

Variable name length should not make any difference. The compiler turns them all into internal pointers when it parses the script.

Shorthand notations also shouldn't make much difference, the compiler should generate similar code for both.

Your concerns all seem to be based on the assumption that the code is being interpreted line by line. PHP is compiled, not interpreted.

他のヒント

None of these matters affect performance at all.

You are looking dramatically wrong way for the improving performance.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top