I saw someone ask if ‘for’ or ‘foreach’ is faster. I was surprised. My code is often slow when I first write it, but it’s never something that could have been fixed by a microoptimization like that. So I wrote this:
In my code, I find that the most important thing for me to focus on is clarity. Writing clear code gives me the best chance of ever getting correctness, good performance, maintainability, and flexibility for future requirements.
If I try to directly build any of those, the loss of clarity means that I lose in all of them.
Regarding your specific situation, I would write the clearest way possible, then measure the real-world performance of my app, and then optimize where it matters.
It seems elementary to me, and yet I keep seeing folks trying to microoptimize like this. So I figured sharing the idea on my blog might be valuable to you, my audience.