title: Timer function to provide time in nano seconds using C++
body: <p>I wish to calculate the time it took for an API to return a value.
  The time taken for such an action is in the space of nanoseconds. As the API is a C++ class/function, I am using the timer.h to calculate the same:</p>
  <pre><code>  #include &lt;ctime&gt;
    #include &lt;iostream&gt;
  
    using namespace std;
  
    int main(int argc, char** argv) {
  
        clock_t start;
        double diff;
        start = clock();
        diff = ( std::clock() - start ) / (double)CLOCKS_PER_SEC;
        cout&lt;&lt;&quot;printf: &quot;&lt;&lt; diff &lt;&lt;'\n';
  
        return 0;
    }
  </code></pre>
  <p>The above code gives the time in seconds. How do I get the same in nano seconds and with more precision?</p>