Back
Close

Modern C++ idoms and recipes

meshell
12.1K views

Measure Time Intervals

C++11 provides a flexible date and time library as part of the standard library that allows to define time points and time intervals. The library is called chrono and is available in the <chrono> header in the std::chrono namespace.

Exercise

Write a method which measures the execution time of a function
#ifndef MODERN_CPP_MEASURE_DURATION_H
#define MODERN_CPP_MEASURE_DURATION_H
#include <chrono>
namespace modern_cpp {
using time_interval_t = std::chrono::microseconds;
template<typename Func, typename... Args>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Time intervals

Exercise

Define the durations and intervals (i.e. do the TODOs)
#ifndef MODERN_CPP_TIME_INTERVALS_H
#define MODERN_CPP_TIME_INTERVALS_H
#include <chrono>
namespace modern_cpp {
namespace time_intervals {
using namespace std::chrono_literals;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Bonus exercise

Define user defined literals for day/days and week/weeks and use them together with the chrono literals to define the intervals in the exercise above.

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants