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; +}