Last active
December 10, 2016 11:56
-
-
Save IsuraManchanayake/8998abb0d5cb5dd279be61b526e5ae7e to your computer and use it in GitHub Desktop.
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 <ctime> | |
#include <vector> | |
#include <functional> | |
using namespace std; | |
int L = 100000000; | |
int R = 100100000; | |
int C; | |
bool primality(int64_t a) { | |
return true; | |
} | |
void test(function<bool(int64_t)> f) { | |
int c = 0; | |
for(int i = L; i < R; i++) | |
c += f(i); | |
C = c; | |
} | |
double average(function<bool(int64_t)> f, int samplecount) { | |
vector<clock_t> end_ticks(samplecount + 1, clock()); | |
for(int i = 0; i < samplecount; i++) { | |
test(f); | |
end_ticks[i + 1] = clock(); | |
} | |
for(int i = 0; i < samplecount; i++) | |
cout << "test " << i + 1 << " duration : " << (end_ticks[i + 1] - end_ticks[i] + 0.) / CLOCKS_PER_SEC << " s"<< endl; | |
cout << "average of " << samplecount << " test(s) : " << (end_ticks[samplecount] - end_ticks[0] + 0.) / (samplecount * CLOCKS_PER_SEC) << " s" << endl; | |
return (end_ticks[samplecount] - end_ticks[0] + 0.) / (samplecount * CLOCKS_PER_SEC); | |
} | |
#define name(x) (#x) | |
int main() { | |
cout << "primality test using " << name(primality) << "(int64_t)" << endl; | |
cout << "L = " << L << " : " << "R = " << R << endl; | |
average(primality, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment