Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to measure cpp code performace

#include <chrono>

/* Only needed for the sake of this example. */
#include <iostream>
#include <thread>
    
void long_operation()
{
    /* Simulating a long, heavy operation. */

    using namespace std::chrono_literals;
    std::this_thread::sleep_for(150ms);
}

int main()
{
    using std::chrono::high_resolution_clock;
    using std::chrono::duration_cast;
    using std::chrono::duration;
    using std::chrono::milliseconds;

    auto t1 = high_resolution_clock::now();
    long_operation();
    auto t2 = high_resolution_clock::now();

    /* Getting number of milliseconds as an integer. */
    auto ms_int = duration_cast<milliseconds>(t2 - t1);

    /* Getting number of milliseconds as a double. */
    duration<double, std::milli> ms_double = t2 - t1;

    std::cout << ms_int.count() << "ms
";
    std::cout << ms_double.count() << "ms
";
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: properties of loop in c++ and how it works 
Cpp :: viewlist exaple win32 
Cpp :: c++ constructor inheritance 
Cpp :: TCA9548 I2CScanner Arduino 
Cpp :: . Single-line comments start with two forward slashes (//). 
Cpp :: logisch nicht 
Cpp :: cpp fread 
Cpp :: PUBG_APIKEY=<your-api-key npm t 
Cpp :: hackerearth questions siemens 
Cpp :: how to print out a two dimensional array in c++ 
Cpp :: loops in c++ with example 
Cpp :: tan trigonometric function 
Cpp :: Catcoder mars rover solution in c++ 
Cpp :: c++ bind what are placeholders 
Cpp :: error c4001 
Cpp :: set precision on floating numbers 
Cpp :: c++ thread id 
Cpp :: c++ find unused class methods 
Cpp :: access the element of vector point2f c++ 
Cpp :: Implement a currency converter which ask the user to enter value in Pak Rupees and convert in following: in cpp 
Cpp :: labs c++ 
Cpp :: Marin and Photoshoot codeforces solution in c++ 
Cpp :: deal with bad input cpp 
Cpp :: convert c++ to python online 
Cpp :: 16630147 
Cpp :: changing key bindings in visual code not working 
Cpp :: tempcoderunnerfile.cpp:1:1: error: does not name a type 
Cpp :: skip headers while reading text 
Cpp :: converter python to c++ code 
Cpp :: cpp super 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =