[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppClock

(C++) std::clock()

Function for get the tick count of the internal clock. Returns a clock_t struct. Can be found in the header file ctime.

The example below shows how to test the speed of the STL's rand function:

  1. include <iostream>
  2. include <ctime>
int main() { const clock_t begin = std::clock(); for (int i=0; i<10000000; ++i) std::rand(); const clock_t end = std::clock(); std::cout << "Time of STL rand(): " << std::difftime(end,begin) << std::endl; }


Same example using the Boost C++ library

Using boost::timer.

  1. include <iostream>
  2. include <boost/timer.hpp>
int main() { boost::timer t; for (int i=0; i<10000000; ++i) std::rand(); std::cout << t.elapsed() << std::endl; }


Code links



last edited (February 8, 2007) by bilderbikkel, Number of views: 3768, Current Rev: 10 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.