Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Created July 24, 2024 04:36
Show Gist options
  • Save yeiichi/134783045a95dbc3a5f90c57011ff5e1 to your computer and use it in GitHub Desktop.
Save yeiichi/134783045a95dbc3a5f90c57011ff5e1 to your computer and use it in GitHub Desktop.
Stopwatches for Python/C++

Stopwatches for Python/C++

Python

#import time

start = time.time()
# Some scripts
end = time.time()

print(f'{(end-start) * 1000:.2f}ms')

C++

#include <chrono>
#include <iostream>

auto start = std::chrono::system_clock::now();
// Some script
auto end = std::chrono::system_clock::now();

std::chrono::duration<double, std::milli> elapsed = end - start;
std::cout << elapsed.count() << "ms" << std::endl;

// https://stackoverflow.com/a/72899799/11042987
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment