Skip to content

Instantly share code, notes, and snippets.

@PaulChana
Created April 14, 2016 08:05
Show Gist options
  • Save PaulChana/7edd2e1238188c57ce924161cb05d3aa to your computer and use it in GitHub Desktop.
Save PaulChana/7edd2e1238188c57ce924161cb05d3aa to your computer and use it in GitHub Desktop.
Timing function C++11
#include <iostream>
#include <cmath>
#include <iomanip>
#include <chrono>
int fun(const int a, const int b, const int c) {
return a * b * c;
}
int main(int argc, const char * argv[]) {
for (int i = 0; i < 101; i++) {
float x = static_cast<float>(i) / 100.f;
auto start = std::chrono::steady_clock::now();
auto t1 = fun(i, i * 5, i * 10);
auto end = std::chrono::steady_clock::now();
std::cout << "T1 -> " << std::chrono::duration <double, std::nano> (end - start).count();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment