Original Post
I've designed my own interfaces for containers and iterators. I wanted to support polymorphic iterators because I think they are neat and I've created a rather basic interface for a container that enables generic iterations through the container, i.e. any container can be iterated through without knowing its exact type. This in turn enables the ability to create tree structures etc. that can use any container for its children and data without the necessity to have multiple implementations of the tree iterators, which is also neat.. Anyway, I also created a basic static array container to test the performance of my code. I was rather suprised to find out that iteration through the elements of the container is almost ten times as slow as with the vector class in the standard library. I thought it had to do with the overhead of using a polymorphic iterator, it means one extra level of indirection as I had to use a smart-pointer to take care of the deletion of the iterator pointer. Then I thought that inlining some functions would help but that resulted in same or even slower execution (!). Now it really bothers me so I tried removing one level of indirection by using the iterator pointer directly.. and the performance gets even worse. Now I'm really confused, does it have to do with the compilers ability to optimize the code? Maybe it optimizes the code better under certain cicumstances that are not obvious to the programmer? My second guess is that it has to do with the profiler. I'm using DevPartner community edition, anyone know how reliable it is? Just wanted to share my experiences and hear if anyone might have any comments.