How to find runtime efficiency of a C++ code
<p>I'm trying to find the efficiency of a program which I have recently posted on stackoverflow.</p>

<p><a href="https://stackoverflow.com/questions/39139341/how-to-efficiently-delete-elements-from-a-vector-given-an-another-vector#39139590">How to efficiently delete elements from a vector given an another vector</a></p>

<p>To compare the efficiency of my code with other answers I'm using <code>chrono</code> object.</p>

<p>Is it a correct way to check the runtime efficiency? </p>

<p>If not then kindly suggest a way to do it with an example.</p>

<p><a href="http://coliru.stacked-crooked.com/a/61408fa2bed3d72c" rel="nofollow noreferrer">Code on Coliru</a></p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;chrono&gt;
#include &lt;ctime&gt;
using namespace std;

void remove_elements(vector&lt;int&gt;&amp; vDestination, const vector&lt;int&gt;&amp; vSource) 
{
    if(!vDestination.empty() &amp;&amp; !vSource.empty())
    {
        for(auto i: vSource) {
            vDestination.erase(std::remove(vDestination.begin(), vDestination.end(), i), vDestination.end());
        }
    }
}

int main() {
    vector&lt;int&gt; v1={1,2,3};
    vector&lt;int&gt; v2={4,5,6};
    vector&lt;int&gt; v3={1,2,3,4,5,6,7,8,9};
    std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
    remove_elements(v3,v1);
    remove_elements(v3,v2);
    std::chrono::steady_clock::time_point end= std::chrono::steady_clock::now();
    std::cout &lt;&lt; "Time difference = " &lt;&lt; std::chrono::duration_cast&lt;std::chrono::nanoseconds&gt;(end - begin).count() &lt;&lt;std::endl;
    for(auto i:v3)
        cout &lt;&lt; i &lt;&lt; endl;
    return 0;
}
</code></pre>

<p><strong>Output</strong> </p>

<pre><code>Time difference = 1472
7
8
9
</code></pre>