[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppClock
The example below shows how to test the speed of the STL's rand function:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
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:
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; }
- include <iostream>
- include <ctime>
Same example using the Boost C++ library
Using boost::timer.int main() { boost::timer t; for (int i=0; i<10000000; ++i) std::rand(); std::cout << t.elapsed() << std::endl; }
- include <iostream>
- include <boost/timer.hpp>
Code links
- #include
- char
- const
- cout
- ctime (header file)
- difftime
- endl
- for
- include
- int
- iostream (header file)
- main
- std
- std::cout
- std::difftime
- std::endl
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
