Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::clock_t

 

std::clock_t is an STL struct for storing time.

 

std::clock_t is defined in the header file ctime.h.

 

#include <cstdlib>
#include <ctime>
#include <iostream>

int main()
{
  const std::clock_t begin = std::clock();
  for (int i=0; i!=10000000; ++i) std::rand();
  const std::clock_t end = std::clock();
  const double n_seconds = std::difftime(end,begin) / CLOCKS_PER_SEC;
  std::cout << "Elapsed time: " << n_seconds << " seconds\n";
}

 

Screen output (elapsed time might differ):

 

Elapsed time: 0.16 seconds

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict