In C++ 11 you can use std::chrono::system_clock::now()
Example (copied from en.cppreference.com):
#include <iostream> #include <chrono> #include <ctime> int main() { auto start = std::chrono::system_clock::now(); // Some computation here auto end = std::chrono::system_clock::now(); std::chrono::duration<double> elapsed_seconds = end-start; std::time_t end_time = std::chrono::system_clock::to_time_t(end); std::cout << "finished computation at " << std::ctime(&end_time) << "elapsed time: " << elapsed_seconds.count() << "s\n"; }
This should print something like this:
finished computation at Mon Oct 2 00:59:08 2017 elapsed time: 1.88232s
Related Posts:
- How to get current time and date in C++?
- timestamp of time(0) at multiple places in a C++ program
- How to get current time in milliseconds?
- How to create a dynamic array of integers
- How to implement 2D vector array?
- What is the difference between g++ and gcc?
- What is the best way to use a HashMap in C++?
- What is the difference between float and double?
- How do I find the length of an array?
- Making my own toString() method on c++ struct
- Struct Constructor in C++?
- What is meant with “const” at end of function declaration? [duplicate]
- What’s the C++ version of Java’s ArrayList
- Java string to date conversion
- What is the difference between “long”, “long long”, “long int”, and “long long int” in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- How do I convert a double into a string in C++?
- How to create timer events using C++ 11?
- How to concatenate two strings in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- Read file line by line using ifstream in C++
- Virtual/pure virtual explained
- error: redefinition of class
- Officially, what is typename for?
- What does T&& (double ampersand) mean in C++11?
- C++ – No matching member function for call to ‘push_back’
- error: lvalue required as unary & operand
- C/C++ JSON parser
- C++ Parsing input string to variables
- ‘cout’ was not declared in this scope
- Segmentation fault error 11 C++
- Why doesn’t C++ have a garbage collector?
- How does ifstream’s eof() work?
- Exception Handling in C++ Terminate called after throwing an instance of ‘char const*’
- how to define -std=c++11 as default in g++
- “g++” is not recognized as an internal or external command, MinGW
- getline() does not work if used after some inputs
- Passing a 2D array to a C++ function
- ‘typeid’ versus ‘typeof’ in C++
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- Thread pooling in C++11
- Callback functions in C++
- Reading from text file until EOF repeats last line
- How does std::forward work? [duplicate]
- Examples of good gotos in C or C++
- Sleep function in C++
- Getting error “a nonstatic member reference must be relative to a specific object” while both member are in the same class
- Division in C++
- How to iterate over a vector?
- Error: Jump to case label in switch statement
- What does int & mean
- Split a string into an array in C++
- splitting a string into an array in C++ without using vector
- Remove spaces from std::string in C++
- How to use glOrtho() in OpenGL?
- error: ‘ostream’ does not name a type
- Remove spaces from std::string in C++
- Read data from a file into an array – C++
- Unknown override specifier, missing type specifier
- error: overloaded ‘operator<<' must be a binary operator (has 3 parameters)
- Process returned -1073741571 (0xC00000FD) on my c++ code
- C++ Fractions Class
- #pragma once vs include guards?
- Debug vs Release in CMake
- C++ Remove punctuation from String
- prototype for “….” does not match any in class “…”
- Cannot open Windows.h in Microsoft Visual Studio
- Nested For – Loops to create multiplication table C++
- The system cannot find the file specified. in Visual Studio
- to_string not declared in scope
- I get this error: “glibc detected”
- How can I get and use the header file
in my C++ program? - cin.eof() functionality
- Implementing a tree in C++
- Drawing Circle with OpenGL
- Run-Time Check Failure #2 – Stack around the variable ‘foo’ was corrupted
- How to implement “Press Any Key To Exit”
- Reading and writing binary file
- GCC -fPIC option
- initialize a vector to zeros C++/C++11
- What is the source of the data for the ProgramFiles, ProgramW6432Dir, ProgramFilesDir (x86), CommonProgramFiles environment variables?
- C++ : Exception occurred in script: basic_string::_S_construct NULL not valid
- Xcode 11.1: iostream’ file not found
- non-member function cannot have cv-qualifier
- too many initializers for ‘int [0]’ c++
- function does not take 1 arguments c++
- overloaded function with no contextual type information
- How exactly do lookup tables work and how to implement them?
- Vector declaration “expected parameter declarator”
- C++ Destructors with Vectors, Pointers,
- error C2065: ‘cout’ : undeclared identifier
- How to get the MD5 hash of a file in C++?
- Why do I get: -9223372036854775808
- Return a 2d array from a function
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- What is the difference among ios::app, out, and trunc in c++?
- Where can I find ‘winmm.lib’ (I’m using Visual Studio 2012)
- What is a `char*`?
- Does static constexpr variable inside a function make sense?
- “Incomplete type not allowed ” when creating std::ofstream objects