[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppDifftime
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]
CppDifftime
(C++) difftime
Function returning the difference between two std::clock_t structs.The example below shows how to test the speed of the STL's rand function:
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(); std::cout << "Time of STL rand(): " << std::difftime(end,begin) << " miliseconds" << std::endl; }
- include <iostream>
- include <ctime>
Same example using the Boost C++ library
int main() { boost::timer t; for (int i=0; i<10000000; ++i) std::rand(); std::cout << "Time elapsed: " << t.elapsed() << " seconds" <<std::endl; }
- include <iostream>
- include <boost/timer.hpp>
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
