#include <iostream>
#include <iomanip>
#include <chrono>
#include <ctime>
#include <thread>
// the function f() does some time-consuming work
void f()
{
volatiledouble d = 0;
for(int n=0; n<10000; ++n)
for(int m=0; m<10000; ++m)
d += d*n*m;
}
int main()
{
auto t_start = std::chrono::high_resolution_clock::now();
std::thread t1(f);
std::thread t2(f); // f() is called on two threads
t1.join();
t2.join();
auto t_end = std::chrono::high_resolution_clock::now();
std::cout << "Wall clock time passed: "
<< std::chrono::duration<double, std::milli>(t_end-t_start).count()
<< " ms\n";
}
I don't understand the count() in this instruction:
I investigated a bit here: http://www.cplusplus.com/reference/algorithm/count/
It looks like the function count() compares a range of values with a specific one. This does not make sense for me in this instruction.
Does anybody know what the purpose of count() in the program is?
Thanks
The way I understand it is that you create a duration object that use a double to store the time duration in milliseconds, and then you use count() to extract that value.