Click here to Skip to main content
12,635,649 members (25,891 online)
Click here to Skip to main content

Stats

71.3K views
197 downloads
26 bookmarked
Posted

find_first_of: A performance pitfall among the STL algorithms

, 18 Jun 2007 CPOL
This article is discussing the performance problems found in the most notable find_first_of implementations and suggests useful improvements and workarounds.
#ifndef __FIND_FIRST_OF_TEST_H__
#define __FIND_FIRST_OF_TEST_H__

#include <string>
#include <iostream>
#include <ctime>

typedef std::string test_string;

enum algo_type
{
	alg_void = 0,
	alg_find_first_of,
	alg_strpbrk,
	alg_find_first_of_set,
	alg_find_first_of_hash_set,
	alg_find_first_of_assoc_vec,
	alg_find_first_of_sorted_range,
	alg_dpx_find_first_of
};

void algo_test(algo_type type, unsigned long test_cycles, unsigned long search_size, unsigned long elements_count, std::ostream *outStream);
clock_t run_algo(algo_type type, const test_string &search_range, const test_string &search_elements, unsigned long test_cycles);

#define ARRAY_SIZE(X)	(sizeof (X) / sizeof (*(X)) )
#define ARRAY_END(X)	( (X) + ARRAY_SIZE(X) )

#endif //__FIND_FIRST_OF_TEST_H__

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.

License

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

Share

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.

You may also be interested in...

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