Hi!

>> In theory, this should be a general performance win any time one
>> needs to iterate over only the keys of an iterable, because it does
>> not require the use of an O(n) iteration and building of the array
>> that array_keys() would, plus it works on non-array types (such as
>> generators or iterators). It also is more performant than
>> foreach($iterable as $key => $_) {}, because it omits the opcode
>> that instructs the engine to retrieve the value. (Presumably, a
>> future direction could include using this request to inform
>> generators or

To me, it looks like the case of premature micro-optimization. Unless
there's a benchmark that proves it achieves speedup in a real-life
application (not tight-loop synthetic benchmark) I think
foreach($iterable as $key => $_) {} is completely fine. My opinion has
been and remains, absent new data, that if your code performance hinges
on a couple of simple opcodes being there, maybe you'd better implement
that part in C, but in most real-life applications it is not and any
performance gain you might get from such syntax is microscopic.

-- 
Stas Malyshev
smalys...@gmail.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to