Matlab tic and toc commands implemented in C++
So as you are using c++ you should use the stl for that

#include &lt;chrono&gt;
#include &lt;iostream&gt;
int main() {
    std::chrono::high_resolution_clock::time_point start, end;

    start = std::chrono::high_resolution_clock::now();    
    /* do someting */
    end = std::chrono::high_resolution_clock::now();
    double time_elapsed = std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;( end - start ).count();
    std::cout &lt;&lt; "Code took " &lt;&lt; time_elapsed &lt;&lt; " miliseconds to execute\n";
};


EDIT

So here an more extended version 

#include &lt;chrono&gt;
#include &lt;iostream&gt;

std::chrono::high_resolution_clock::time_point start_timer() {
    return std::chrono::high_resolution_clock::now();
}

void stop_timer (clock::time_point &amp;start, std::string &amp;message) {
    using cast = std::chrono::duration_cast;
    auto duration = cast&lt;std::chrono::milliseconds&gt;(std::chrono::high_resolution_clock::now() - start);
    auto hours    = cast&lt;std::chrono::hours&gt;(duration).count();
    duration     -= cast&lt;std::chrono::milliseconds&gt;(hours);
    auto minutes  = cast&lt;std::chrono::minutes&gt;(duration).count();
    duration     -= cast&lt;std::chrono::milliseconds&gt;(minutes);
    auto seconds  = cast&lt;std::chrono::minutes&gt;(duration).count();
    duration     -= cast&lt;std::chrono::milliseconds&gt;(seconds);

    std::cout &lt;&lt; "The code took ";
    if (hours &gt;= 1) {
        std::cout &lt;&lt; std::lrint(hours) &lt;&lt; "h";
    }
    if (minutes &gt;= 1) {
        std::cout &lt;&lt; std::lrint(minutes) &lt;&lt; "m";
    }
    if (seconds &gt;= 1) {
        std::cout &lt;&lt; std::lrint(seconds) &lt;&lt; "s";
    }
    if (milliseconds &gt;= 1) {
        std::cout &lt;&lt; std::lrint(duration) &lt;&lt; "ms";
    }
    std::cout &lt;&lt; " to execute\n";
}


int main() {
    std::chrono::high_resolution_clock::time_point start = start_timer();    
    /* do someting */
    stop_timer(start);
}