DEV Community

loading...

Discussion on: A Slow Death by For Loops

Collapse
vasilvestre profile image
Valentin Silvestre

I think you do not use the right tool, to manipulate multiple sources of data and output the data, I use Talend Open Studio for Big Data.
It's free, work great and easy to learn.

(I don't think that you really don't use the right tool, I just think that there's better tool)

Anyway talking about your loop, I use foreach() whenever I can because it's kinda same as fori() but easier to use.

Collapse
bengreenberg profile image
Ben Greenberg Author

Yes, I agree there are some great tools out there for managing multiple sources of data, but sometimes we are limited by the business specifications. I also agree that foreach() looks a lot nicer than a for() loop, but I'm not 100% sure that it is faster than a for() loop with the length calculated in advance. I've seen a lot written about that subject with various benchmarks going both ways. Of course, in most situations, the difference will be negligible either way.

Collapse
vasilvestre profile image
Valentin Silvestre

As you can see here : 3v4l.org/7Kvf5 , PHP7 made foreach() 50% as fast as for(). It depend of version tho
To be honest, that's premature optimisation to use for() instead of foreach() from now. If you really need high-performance, you shouldn't use PHP imo

Thread Thread
yechielk profile image
Yechiel Kalmenson

Unfortunately, sometimes those decisions are made for you by others...

Thread Thread
vasilvestre profile image
Valentin Silvestre

Sometimes it's worth mentionning the fact that with low effort, you can improve a lot the process and (because that's the only thing that interest people) the result