Click here to Skip to main content
11,495,319 members (68,115 online)
Click here to Skip to main content
Add your own
alternative version

find_first_of: A performance pitfall among the STL algorithms

, 18 Jun 2007 CPOL 62.1K 183 26
This article is discussing the performance problems found in the most notable find_first_of implementations and suggests useful improvements and workarounds.
#include "find_first_of_test.h"
#include <fstream>

void TestA(algo_type type, std::ostream *outStreamPtr)
unsigned long element_count_array[] = { 1, 2, 4, 8, 16, 32, 48, 64 };

	unsigned long test_cycles		= 10;
	unsigned long test_cycles		= 1;
	unsigned long search_size		= 10000000;

	unsigned long *it = NULL;

	for ( it = element_count_array; it != ARRAY_END(element_count_array); ++it)
		algo_test(type, test_cycles, search_size, *it, outStreamPtr);

int main(int argc, char* argv[])
	std::ofstream outfile;
	if (argc == 2)[1], std::ios::app);
	std::ostream *outStream = outfile.is_open() ? &outfile : &std::cout;

	TestA(alg_find_first_of, outStream);
	TestA(alg_strpbrk, outStream);
	TestA(alg_dpx_find_first_of, outStream);
	TestA(alg_find_first_of_set, outStream);
	TestA(alg_find_first_of_hash_set, outStream);
	TestA(alg_find_first_of_sorted_range, outStream);
	//TestA(alg_find_first_of_assoc_vec, outStream);

	return 0;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jim Xochellis
Software Developer
Greece Greece
I live in Greece with my wife and our two daughters. I am a professional software developer since 1999, using mostly C/C++ in my work.

My main expertise are: C/C++, STL, software optimization, generic programming and debugging. I am also very experienced in client–server programming, communications, concurrent programming, software security and cryptography. Finally, in my early professional years, I have worked a lot on cross-platform programming (Mac+Win).

I am familiar with the MFC, wxWidgets and Cplat GUI frameworks and the Python, Java, Pascal, Fortran, Prolog and Rexx programming languages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 18 Jun 2007
Article Copyright 2007 by Jim Xochellis
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid