How do I call clock() in C++?
For example, I want to test how much time a linear search takes to find a given element in an array.
How do I call clock() in C++?
For example, I want to test how much time a linear search takes to find a given element in an array.
You can measure how long your program works. The following functions help measure the CPU time since the start of the program:
(double)clock() / CLOCKS_PER_SEC with ctime included.time.clock() returns floating-point value in seconds.System.nanoTime() returns long value in nanoseconds.My reference: algorithms toolbox week 1 course part of data structures and algorithms specialization by University of California San Diego & National Research University Higher School of Economics
So you can add this line of code after your algorithm:
cout << (double)clock() / CLOCKS_PER_SEC;
Expected Output: the output representing the number of clock ticks per second