Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Last active August 29, 2015 14:27
Show Gist options
  • Save cengiz-io/917ef8d934c201d63982 to your computer and use it in GitHub Desktop.
Save cengiz-io/917ef8d934c201d63982 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct measure {
template<typename F, typename ...Args>
static void execution(F func, Args&&... args) {
auto start = chrono::system_clock::now();
func(forward<Args>(args)...);
auto duration = chrono::system_clock::now() - start;
cout << "Elapsed: " << duration.count() / 1000 << "ms" << endl;
}
};
bool isDivisibleBy1To20(long n) {
if (n % 20 != 0) {
return 0;
}
for (int i = 11; i <= 20; i++) {
if (n % i != 0) {
return 0;
}
}
return 1;
}
int main() {
long x = 1;
measure::execution([&x]() {
while (x++) {
if (isDivisibleBy1To20(x)) {
cout << "Number is " << x << endl;
break;
}
}
});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment