Difference between revisions of "Template:cpp/chrono/clock/now"
From cppreference.com
(don't use ddcl) |
(Added comments) |
||
Line 29: | Line 29: | ||
{ | { | ||
for (unsigned long long size = 1; size < 10000000; size *= 10) { | for (unsigned long long size = 1; size < 10000000; size *= 10) { | ||
− | |||
− | |||
− | |||
− | auto elapsed = end - start; | + | auto start = std::chrono::{{{1}}}::now(); // a "timepoint" representing now |
− | std::cout << size << ": " << elapsed.count() << '\n'; | + | |
+ | std::vector<int> v(size, 42); // something that takes some time to do | ||
+ | |||
+ | auto end = std::chrono::{{{1}}}::now(); // the new current "timepoint" | ||
+ | |||
+ | auto elapsed = end - start; // difference is a "duration" | ||
+ | |||
+ | std::cout << size << ": " << elapsed.count() << '\n'; // clock ticks (seconds) | ||
} | } | ||
} | } |
Revision as of 14:19, 20 April 2014
static std::chrono::time_point<std::chrono::{{{1}}}> now(); |
(since C++11) | |
Returns a time point representing with the current point in time.
Contents |
Parameters
(none)
Return value
A time point representing the current time.
Exceptions
noexcept specification:
noexcept
Example
Run this code
#include <iostream> #include <vector> #include <chrono> int main() { for (unsigned long long size = 1; size < 10000000; size *= 10) { auto start = std::chrono::{{{1}}}::now(); // a "timepoint" representing now std::vector<int> v(size, 42); // something that takes some time to do auto end = std::chrono::{{{1}}}::now(); // the new current "timepoint" auto elapsed = end - start; // difference is a "duration" std::cout << size << ": " << elapsed.count() << '\n'; // clock ticks (seconds) } }
Possible output:
1: 1 10: 2 100: 3 1000: 6 10000: 47 100000: 507 1000000: 4822