what does the function count() do?

This the program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <iomanip>
#include <chrono>
#include <ctime>
#include <thread>
 
// the function f() does some time-consuming work
void f()
{
    volatile double 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:
 
std::chrono::duration<double, std::milli>(t_end-t_start).count()


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
Last edited on
This is the count function you should be looking at: http://www.cplusplus.com/reference/chrono/duration/count/

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.
Thanks @Peter87
Topic archived. No new replies allowed.