-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize FileLocator autoloader : use foreach instead of for with count when possible #3280
optimize FileLocator autoloader : use foreach instead of for with count when possible #3280
Conversation
Sorry for the silly question but is |
previously, with |
Yes, I understand this part, but isn't |
direct foreach is faster. Example benchmark about |
|
I get quite different results to be honest
Also checked it on sandbox: https://phpsandbox.io/n/red-king-pnbr |
The code that I updated previosly uses count+for, so foreach still win |
Not really. "For with count()" is when we use for($i = 0; $i < count($elements); $i++) and it's not the case here. |
The benchmark code need update to associative array and run the code inside loop, I updated the benchmark code at https://phpsandbox.io/n/super-fog-72g7 with place assign For took: 0.066ms
For with count() took: 0.167ms
Foreach took: 0.099ms foreach wins on this case. |
Okay, now it looks good. Thanks. |
Checklist: