I felt like this topic deserved one more article. (See part 1 and part 2 for the background.)
The question was posed, "what if you make the list of integers dynamically generated?"
So, I came up with this little generator iterator adaptor. It allows you to take any generator function and treat it like a forward iterator:
#include <iostream> #include <algorithm> template<typename Gen, typename Val, int Size> class generator_itr { private: Gen m_g; Val m_cur; int m_iteration; public:
After the first article on loop optimization my cousin pointed out to me that in some cases, tail recursion can actually be faster then loops in C with the help of tail recursion elimination. It took several tries to come up with a version that the compiler was able to optimize. I knew I got the version correct when the application stopped segfaulting (I believe it was running out of stack space).
I recently had a friend point out to me that your typical loop seen in every day code has minor inefficiencies in it which can add up to a good amount of time being wasted. I agreed with him, so I set out to write an article on how to optimize your C++ loops.
The results of the research for this article surprised me. I'll first cover the optimization techniques:
Recent comments
6 days 23 hours ago
1 week 1 day ago
1 week 1 day ago
1 week 3 days ago
2 weeks 2 days ago
3 weeks 3 days ago
3 weeks 3 days ago
3 weeks 3 days ago
3 weeks 4 days ago
3 weeks 4 days ago