Last active
March 22, 2018 01:01
-
-
Save rahul003/c1c8acda3a93675938c8ab3480b8e013 to your computer and use it in GitHub Desktop.
Timing code snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <chrono> | |
class Timer { | |
public: | |
Timer() : beg_(clock_::now()) {} | |
void reset() { beg_ = clock_::now(); } | |
double elapsed() const { | |
return std::chrono::duration_cast<second_> | |
(clock_::now() - beg_).count(); } | |
private: | |
typedef std::chrono::high_resolution_clock clock_; | |
typedef std::chrono::duration<double, std::ratio<1> > second_; | |
std::chrono::time_point<clock_> beg_; | |
}; | |
int main() { | |
Timer t; | |
int num = 1000000000; | |
float* a = new float[num]; | |
uint16_t* b = new uint16_t[num]; | |
t.reset(); | |
for (int i=0;i<num; i++) { | |
*(a++) += (float) *(b++); | |
} | |
std::cout << t.elapsed() << std::endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import default_timer as timer | |
start = timer() | |
# ... | |
end = timer() | |
print(end - start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment