PHP functions to achieve the same function but the speed of the difference is what, why the speed is different?
Reply content:
PHP functions to achieve the same function but the speed of the difference is what, why the speed is different?
The problem of "stepping" more, but I still dare to answer it ... There are examples of two functions doing the same thing in PHP, but almost all because they are aliases (such as sizeof vs. Count,strstr vs. STRCHR). In this case, their performance is exactly the same. You want to, if you already have a function of the same function, why should PHP develop a function that is identical (and at a different speed)?
But if the definition of "function" is relaxed, it can be found that there is such a thing, PHP system function is slower than the other syntax. A typical example is checking whether a string is longer than the specified value. Say no more than 1000.
One way is if (strlen ($STR) <=1000). PHP internally checks if the Len member of this string object is greater than 1000. So not every time the string is counted, the time complexity is O (1).
Another atypical practice is if (!isset ($str [1000])). The time complexity is also O (1), but you will find it several times faster than the strlen test.
Why are the two functions so much worse? Because PHP handles isset, the above expression is converted to just a few virtual machine instructions. This is a bit like Java's intrinsics, although the call function can complete isset tasks, but the function of the relevant instructions inline into the code, the speed can be faster.
And strlen has no such treatment. Call strlen to go to the PHP routine call system function program, frequently hundreds of code. So the speed is much slower than isset.
But note that strlen and isset do not all have the same functionality, but are used to check the string length here, both are competent. So.. Although this example has some far-fetched, but I think it is most in line with your problem standard.