Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- using namespace std;
- using namespace std::chrono;
- size_t foo = 0;
- template<int from, int to> struct Loop {
- inline void operator()() { ++foo; Loop<from+1, to>()(); }
- };
- template<int to> struct Loop<to, to> { void operator()() {} };
- struct Incrementer { void operator()() { ++foo; } };
- int main()
- {
- auto start = high_resolution_clock::now();
- Loop<0, 10000>()();
- auto stop = high_resolution_clock::now();
- size_t duration1 = duration_cast<microseconds>(stop-start).count();
- start = high_resolution_clock::now();
- for(int from=0, to=10000; from < to; ++from) { Incrementer()(); }
- stop = high_resolution_clock::now();
- size_t duration2 = duration_cast<microseconds>(stop-start).count();
- cout << "templated: " << duration1 << ", for: " << duration2 << ", foo: " << foo << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement