O'Reilly logo

Efficient C++ Performance Programming Techniques by David Mayhew, Dov Bulka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Better than STL?

The STL is regarded by many to have excellent performance. The general trend is to discourage the programmer from even thinking about surpassing the STL performance with home-grown implementations. Although we agree with this notion, for the most part, we would still like to take a closer look at those conceptions. To learn more about it, we will take a few shots at exceeding the STL performance and see how it goes.

We have encountered the accumulate() function earlier in this chapter, using it to sum up a collection of integers. Let's see if we can improve upon it with a home-grown implementation:

 int myIntegerSum(int *a, int size) { int sum = 0; int *begin = &a[0]; int *end = &a[size]; for (int *p=begin; p != end; p++) { sum ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required