O'Reilly logo

Boost C++ Application Development Cookbook by Antony Polukhin

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

Comparing strings in an ultra-fast manner

It is a common task to manipulate strings. Here we'll see how the operation of string comparison can be done quickly using some simple tricks. This recipe is a trampoline for the next one, where the techniques described here will be used to achieve constant time-complexity searches.

So, we need to make a class that is capable of quickly comparing strings for equality. We'll make a template function to measure the speed of comparison:

#include <string> template <class T> std::size_t test_default() { // Constants const std::size_t ii_max = 20000000; const std::string s( "Long long long string that " "will be used in tests to compare " "speed of equality comparisons." ); // Making some data, that will be // ...

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