How do I call clock() in C++?
clock()
C++
For example, I want to test how much time a linear search takes to find a given element in an array.
#include <iostream> #include <cstdio> #include <ctime> int main() { std::clock_t start; double duration; start = std::clock(); /* Your algorithm here */ duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; std::cout<<"printf: "<< duration <<' '; }
2.1m questions
2.1m answers
60 comments
57.0k users