From 06a4584ca2bee48f90ea35e12d07f63ae212e04e Mon Sep 17 00:00:00 2001 From: Morten Nobel-Joergensen Date: Tue, 31 Jul 2018 12:05:21 +0200 Subject: [PATCH] Add chrono --- README.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3360a04..23ad9d4 100644 --- a/README.md +++ b/README.md @@ -447,7 +447,7 @@ a.first; // "hello" a.second; // 3 ``` -## `map` (associative array - usually implemented as binary search trees) +## `map` (associative array - usually implemented as binary search trees - avg. time complexity: O(log n)) ```cpp #include // Include map (std namespace) @@ -458,7 +458,7 @@ for (auto& p:a) a.size(); // 1 ``` -## `unordered_map` (associative array - usually implemented as hash table) +## `unordered_map` (associative array - usually implemented as hash table - avg. time complexity: O(1)) ```cpp #include // Include map (std namespace) @@ -469,7 +469,7 @@ for (auto& p:a) a.size(); // 1 ``` -## `set` (store unique elements - usually implemented as binary search trees) +## `set` (store unique elements - usually implemented as binary search trees - avg. time complexity: O(log n)) ```cpp #include // Include set (std namespace) @@ -480,7 +480,7 @@ if (s.find(123) != s.end()) // Search for an element cout << s.size(); // Number of elements in set ``` -## `unordered_set` (store unique elements - usually implemented as a hash set) +## `unordered_set` (store unique elements - usually implemented as a hash set - avg. time complexity: O(1)) ```cpp #include // Include set (std namespace) @@ -501,3 +501,18 @@ sort(a, a+n); // Sort array a[0]..a[n-1] by < sort(a.begin(), a.end()); // Sort vector or deque reverse(a.begin(), a.end()); // Reverse vector or deque ``` + +## 'chrono' (Time related library) +```cpp +#include // Include chrono +using namespace chrono; // Use namespace +auto from = // Get current time_point + high_resolution_clock::now(); +// ... do some work +auto to = // Get current time_point + high_resolution_clock::now(); +using ms = // Compute duration in milliseconds + duration; +cout << duration_cast(to - from) + .count() << "ms"; +```