std::string::find vs std::find

Joined
Jul 5, 2009
Messages
2
Reaction score
0
Hi All:

I have a large number of elements to be stored into vector or basic string(delimited by \n). I need to search for an element and I would like to know what is faster:

A:
Code:
std::string str = "\nElement1\nElement2...element10000\n"
str.find("\nElement3\n");

B:
Code:
std::vector<string> v;
v.push_back("Element1"); v.push_back("Element2");  ....
std::find(v.begin(), v.end(), "Element3") != v.end() )

I'm only interested in search time, I don't need to access any of the elements for reading, modifying or removing.

Thanks a lot,
Petry
 
Joined
Jul 5, 2009
Messages
2
Reaction score
0
I have just tested the difference.

Filesize: 8mb
Lines: 700.000
Average line lenght: 15 characters

Time to fill:
vector: 3843ms
string: 3891ms

The search time for the last unique element is:
vector: 218
string: 172
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top