I've taken this example from B.Stroustrup's new book "TCPL" at page 119.
#include <iostream> #include <thread> //#include <chrono> //using namespace std::chrono; // see §35.2 int main() { auto t0 = std::chrono::high_resolution_clock::now(); std::this_thread::sleep_for(std::chrono::milliseconds{20}); auto t1 = std::chrono::high_resolution_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(t1-t0).count() << " nanoseconds passed\n"; }
I have two questions about this code:
- Why the need for a sub-namespace std::chrono?
- In clang and gcc the output is about 20.1 millions nanoseconds. For VS2013 is 27.2 millions nanoseconds. Any explanation for such a big difference?