Which is faster: rewrite the existing value of an object property or create a variable and write values to it in PHP?
- 6Let me not believe that you have already tested and found that this is a problem. Do not fool your head, do as it is clearer and more convenient. - VladD
- one@VlaD, in order to verify that exactly IT is a bottleneck, it is not always necessary to conduct tests. I asked the question, did you tell me the same way - were the tests carried out? Those. I need to completely rewrite and check everything in order to make sure that this method is a “brake” compared to the current one? Despite the fact that this may take more than one month? On this issue - 5 minutes for tests, but in general - a dubious approach. The fact that you are going to check someone has already checked and ask him is not difficult, but it will help save a lot of time. - BOPOH
- 2@BOPOH: Because this is the right answer to any optimization question. Any code will be faster, depending on the OS, optimizer, memory load, processor frequency, memory performance, wind direction and moon phase. A much more serious question and a necessary question is not how to make the code fast , but how to make it correct . The correct semantics is two orders of magnitude more important than micro-optimization. - VladD
- one@VladD, @RAVON, note that the author did not ask how to do it right? , and simply asked what in FP? . Maybe it would be better to first answer a specific question, and only then talk about the cost of the developer’s precious time for this or that optimization? Personally, I do not know the right answer. Based on general considerations on the implementation of interpreters and assuming optimal implementation of PCP (in the sense of micro-optimization of performance), I think that rewriting an existing value is faster . - avp
- 2The part of the code that wants to optimize the TS is executed only once, and not in a loop of 100k iterations, because in order to create a new variable in a loop 100k instead of overwriting an existing one, you need to try pretty hard. It is not clear why bother with such "optimizations". Although if you raise the server on the microwave and run PHP on it, you will probably have to think about such performance losses. - ReinRaus
|
1 answer
Here , for example, someone got confused by a bunch of tests 3-4 years ago, and writes that working with an already initialized variable is 376% faster than with a new one. So The person considers that the answer to your question is: faster, and significantly, to rewrite the properties of an existing object, rather than create a new variable.
- oneThank. There besides this there are still many interesting details. - cheremushkin
|