Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: John-Paul Stewart Newsgroups: comp.lang.php Subject: Re: poor performance while processing a file one byte a time Date: Thu, 20 Jan 2022 12:38:06 -0500 Lines: 12 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net sN+oASXejI9B7307piMxkA7zm65+FqgHKwdxu5wnLOSgPbqqT5 Cancel-Lock: sha1:DbCxj1g+MGqvhQwqKaIgDUw89Wc= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-CA In-Reply-To: Xref: csiph.com comp.lang.php:18850 On 2022-01-20 11:23, Mateusz Viste wrote: > >> (There's nothing specific to PHP about that advice either. It's >> equally applicable to C, although modern C compilers _may_ make that >> optimization for you.) > > That's hardly applicable in C, since there is no "foreach" in C. There > is a "for", and it's initialization argument is processed exactly once. I was speaking more broadly about pulling invariant code out of any and all loops regardless of where it appears in said loop, rather than relying on the interpreter or compiler to handle it for you.