mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-18 18:44:35 +03:00
Improve std::chrono example (#34)
* Improve std::chrono example Closes #32 . @skwllsp arguing makes sense, so the example can be updated to use steady_clock or it could guarantee that the system clock is steady using `std::chrono::system_clock::is_steady`, but I don't think that would simplify things.
This commit is contained in:
committed by
Anthony Calandra
parent
687c0ce558
commit
21c9492403
6
CPP11.md
6
CPP11.md
@@ -652,10 +652,10 @@ baz(p1);
|
|||||||
### std::chrono
|
### std::chrono
|
||||||
The chrono library contains a set of utility functions and types that deal with _durations_, _clocks_, and _time points_. One use case of this library is benchmarking code:
|
The chrono library contains a set of utility functions and types that deal with _durations_, _clocks_, and _time points_. One use case of this library is benchmarking code:
|
||||||
```c++
|
```c++
|
||||||
std::chrono::time_point<std::chrono::system_clock> start, end;
|
std::chrono::time_point<std::chrono::steady_clock> start, end;
|
||||||
start = std::chrono::system_clock::now();
|
start = std::chrono::steady_clock::now();
|
||||||
// Some computations...
|
// Some computations...
|
||||||
end = std::chrono::system_clock::now();
|
end = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
std::chrono::duration<double> elapsed_seconds = end-start;
|
std::chrono::duration<double> elapsed_seconds = end-start;
|
||||||
|
|
||||||
|
|||||||
@@ -1201,10 +1201,10 @@ baz(p1);
|
|||||||
### std::chrono
|
### std::chrono
|
||||||
The chrono library contains a set of utility functions and types that deal with _durations_, _clocks_, and _time points_. One use case of this library is benchmarking code:
|
The chrono library contains a set of utility functions and types that deal with _durations_, _clocks_, and _time points_. One use case of this library is benchmarking code:
|
||||||
```c++
|
```c++
|
||||||
std::chrono::time_point<std::chrono::system_clock> start, end;
|
std::chrono::time_point<std::chrono::steady_clock> start, end;
|
||||||
start = std::chrono::system_clock::now();
|
start = std::chrono::steady_clock::now();
|
||||||
// Some computations...
|
// Some computations...
|
||||||
end = std::chrono::system_clock::now();
|
end = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
std::chrono::duration<double> elapsed_seconds = end-start;
|
std::chrono::duration<double> elapsed_seconds = end-start;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user