Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::chrono...i_clock::now(3) C++ Standard Libarystd::chrono...i_clock::now(3)

NAME
       std::chrono::tai_clock::now - std::chrono::tai_clock::now

Synopsis
	  static     std::chrono::time_point<std::chrono::tai_clock>	now();
       (since C++20)

	  Returns a time point representing the	current	point in time. The re-
       sult is
	  calculated		     as			if		    by
       std::chrono::tai_clock::from_utc(std::chrono::utc_clock::now()).
	  Implementations may use a more accurate value	of TAI time.

Parameters
	  (none)

Return value
	  A time point representing the	current	time.

Example
       // Run this code

	#include <iostream>
	#include <iomanip>
	#include <vector>
	#include <numeric>
	#include <chrono>

	volatile int sink;
	int main()
	{
	    std::cout << std::fixed << std::setprecision(9) << std::left;
	    for	(auto size = 1ull; size	< 1000'000'000ull; size	*= 100)	{
		// record start	time
		auto start = std::chrono::tai_clock::now();
		// do some work
		std::vector<int> v(size, 42);
		sink  =	 std::accumulate(v.begin(), v.end(), 0u); // make sure
       it's a side effect
		// record end time
		auto end = std::chrono::tai_clock::now();
		std::chrono::duration<double> diff = end - start;
		std::cout << "Time to fill  and	 iterate  a  vector  of	 "  <<
       std::setw(9)
			  << size << " ints : "	<< diff.count()	<< " s\n";
	    }
	}

Possible output:
	Time to	fill and iterate a vector of 1	       ints : 0.000006568 s
	Time to	fill and iterate a vector of 100       ints : 0.000002854 s
	Time to	fill and iterate a vector of 10000     ints : 0.000116290 s
	Time to	fill and iterate a vector of 1000000   ints : 0.011742752 s
	Time to	fill and iterate a vector of 100000000 ints : 0.505534949 s

http://cppreference.com		  2022.07.31	 std::chrono...i_clock::now(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::chrono::tai_clock::now&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help