Skip to content

Instantly share code, notes, and snippets.

@buchgr
Created November 30, 2014 15:14
Show Gist options
  • Save buchgr/09948400c6487f00ef88 to your computer and use it in GitHub Desktop.
Save buchgr/09948400c6487f00ef88 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstdlib>
#include "cycle.h"
const short NFUNCS = 24;
template<int N>
int fN(int x) {
return fN<N-1>(fN<N-1>(x));
}
template<>
int fN<0> (int x) {
return (x + 23) >> 2;
}
int main (int argc, char *argv[]) {
int iterations = atoi(argv[1]);
ticks start = getticks();
int result = 0;
int i = iterations;
while (i --> 0) {
result += fN<NFUNCS>(i);
}
ticks end = getticks();
double total = elapsed(end, start);
double percall = total / ( (1 << (NFUNCS+1)) - 1) / iterations;
printf("total cycles: %.2f, cycles per call: %.2f\n", total, percall);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment