Skip to content

Instantly share code, notes, and snippets.

@certik
Created July 20, 2011 22:33
Show Gist options
  • Select an option

  • Save certik/1096098 to your computer and use it in GitHub Desktop.

Select an option

Save certik/1096098 to your computer and use it in GitHub Desktop.
// Compile with:
// gcc -O3 -march=native -ffast-math -funroll-loops b.c
#include "stdio.h"
long sumit(long n)
{
long i = 0, s = 0;
while (i < n) {
s += i;
i++;
}
return s;
}
typedef long (*fn_ptr)(long);
long apply(fn_ptr f, long a)
{
return f(a);
}
int main(void)
{
long i = 0, sum = 0;
fn_ptr s = sumit;
while (i < 100000000) {
sum += apply(s, 10);
i++;
}
printf("%ld\n", sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment