Skip to content

Instantly share code, notes, and snippets.

@xorrbit
Last active October 20, 2016 14:26
Show Gist options
  • Save xorrbit/8a628e6f50d1d6a02072598bb62aa6e3 to your computer and use it in GitHub Desktop.
Save xorrbit/8a628e6f50d1d6a02072598bb62aa6e3 to your computer and use it in GitHub Desktop.
drtest
// profiling results: http://imgur.com/a/lIFSY
// compiled on osx like so:
// gcc -o drtest_no_optimization drtest.c -pg
// gcc -o drtest_with_ofast drtest.c -pg -Ofast
// gcc -o drtest_with_otwo drtest.c -pg -O2
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define NUM_POINTS 100000000
double point1[NUM_POINTS], point2[NUM_POINTS], mid[NUM_POINTS];
int i;
void __attribute__ ((noinline)) divide_that_shit(void)
{
for(i = 0; i < NUM_POINTS; i++)
{
mid[i] = (point1[i] + point2[i]) / 2.0;
}
}
void __attribute__ ((noinline)) fabs_that_shit(void)
{
for(i = 0; i < NUM_POINTS; i++)
{
mid[i] = fabs(point1[i] - point2[i]);
}
}
int main(void)
{
srand((unsigned)time(NULL));
for(i = 0; i < NUM_POINTS; i++)
{
point1[i] = ((double)rand()/(double)RAND_MAX);
point2[i] = ((double)rand()/(double)RAND_MAX);
}
divide_that_shit();
fabs_that_shit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment