#include <algorithm>
#include <array>
#include <chrono>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
template <size_t N, typename F>
void TestFunc(F lambda)
{
std::array<std::chrono::milliseconds::rep, N> time;
for(int i = 0; i < N; ++i)
{
auto t1 = std::chrono::high_resolution_clock::now();
for(int j = 0; j < 1000; ++j)
{
lambda();
}
auto t2 = std::chrono::high_resolution_clock::now();
time[i] = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
}
auto avg = std::accumulate(begin(time), end(time), (std::chrono::milliseconds::rep)0) / time.size();
std::cout << "Average of " << N << " tests is " << avg << "ms.\n";
}
int main()
{
std::function<int()> f = []()
{
int sum = 0; for(int i = 0; i < 100000; ++i) sum += i; return sum;
};
TestFunc<10>(f);
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGFycmF5PgojaW5jbHVkZSA8Y2hyb25vPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPHZlY3Rvcj4KCnRlbXBsYXRlIDxzaXplX3QgTiwgdHlwZW5hbWUgRj4Kdm9pZCBUZXN0RnVuYyhGIGxhbWJkYSkKewoJc3RkOjphcnJheTxzdGQ6OmNocm9ubzo6bWlsbGlzZWNvbmRzOjpyZXAsIE4+IHRpbWU7CgoJZm9yKGludCBpID0gMDsgaSA8IE47ICsraSkKCXsKCQlhdXRvIHQxID0gc3RkOjpjaHJvbm86OmhpZ2hfcmVzb2x1dGlvbl9jbG9jazo6bm93KCk7CgkJZm9yKGludCBqID0gMDsgaiA8IDEwMDA7ICsraikKCQl7CgkJCWxhbWJkYSgpOwoJCX0KCQlhdXRvIHQyID0gc3RkOjpjaHJvbm86OmhpZ2hfcmVzb2x1dGlvbl9jbG9jazo6bm93KCk7CgkJdGltZVtpXSA9IHN0ZDo6Y2hyb25vOjpkdXJhdGlvbl9jYXN0PHN0ZDo6Y2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