From ca068e5828548998be1962a7237c6b4447b544f0 Mon Sep 17 00:00:00 2001 From: Siddharth M <47861446+siddmohanty@users.noreply.github.com> Date: Sun, 1 Mar 2020 20:17:32 +0530 Subject: [PATCH] Measure time (#706) * Create measure_time_elapsed.cpp * add functionality to measure time elapsed of a code * cout --> std:cout * Update measure_time_elapsed.cpp * Update time_elapsed.cpp * Update measure_time_elapsed.cpp * std:cout << getTimeInMicroseconds() - starttime; * std:cout << getTimeInMicroseconds() - starttime; * Update measure_time_elapsed.cpp * Fix include order and use int64 * Remove trailing whitespace * Delete time_elapsed.cpp * int64_t * #include * long long * int64 * int64_t * __int64_t * std::cout and std::nullptr * #include Co-authored-by: Christian Clauss --- others/measure_time_elapsed.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 others/measure_time_elapsed.cpp diff --git a/others/measure_time_elapsed.cpp b/others/measure_time_elapsed.cpp new file mode 100644 index 000000000..d0830ab79 --- /dev/null +++ b/others/measure_time_elapsed.cpp @@ -0,0 +1,19 @@ +// To calculate the time taken by a code to execute +#include +#include + +__int64_t getTimeInMicroseconds() { + struct timeval start; + gettimeofday(&start, NULL); + return start.tv_sec * 1000000 + start.tv_usec; +} + +// write function sample(args) + +int main() { + // write code + __int64_t starttime = getTimeInMicroseconds(); + // sample(args) function run + // Any other functions (if present) run + std::cout << getTimeInMicroseconds() - starttime; +}