Why is inserting into a set<vector<string>> so slow?
<p>For a class project we are making a simple compiler / Relational Database. Mine produces the correct answers, but too slowly on large queries. I ran visual studio's performance analysis and my program is spending 80% of it's time inserting my tuples (rows in a table) into a set. The function is part of computing a cross product, so the result has lots and lots of rows, but I need suggestions on a faster way to insert my tuples into the set.</p>

<pre><code>for (set&lt;vector&lt;string&gt;&gt;::iterator it = tuples.begin(); it != tuples.end(); ++it)
{
    for (set&lt;vector&lt;string&gt;&gt;::iterator it2 = tuples2.begin(); it2 != tuples2.end(); ++it2)
    {
        vector&lt;string&gt; f(*it);
        f.insert(f.end(), it2-&gt;begin(), it2-&gt;end());
        newTuples.insert(f); //This is the line that takes all the processing time
    }
}
</code></pre>