Skip to content

Instantly share code, notes, and snippets.

@matthew-d-jones
Created February 27, 2020 07:26
Show Gist options
  • Save matthew-d-jones/f2f18da4e6d2c01666974dc57514c746 to your computer and use it in GitHub Desktop.
Save matthew-d-jones/f2f18da4e6d2c01666974dc57514c746 to your computer and use it in GitHub Desktop.
MATLAB-style tictoc, simple timing functions for C++
#pragma once
#include <chrono>
#include <iostream>
using Clock = std::chrono::high_resolution_clock;
static Clock::time_point t0 = Clock::now();
void tic() { t0 = Clock::now(); }
void toc() {
Clock::time_point t1 = Clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0);
auto us = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0);
std::cout << ms.count() << " ms, " << us.count() << " us\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment