Skip to content

Instantly share code, notes, and snippets.

@tomaes
Created March 23, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaes/690868049c4aa81b85e1 to your computer and use it in GitHub Desktop.
Save tomaes/690868049c4aa81b85e1 to your computer and use it in GitHub Desktop.
...turns out PDE is slower than expected; doing the same thing in c99 (-O3'ed) is an order of magnitude faster?
// c99
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#define COUNT 200000000
#define RND_RANGE 200000000
//#define OUTPUT
int32_t ip[COUNT];
int32_t op[RND_RANGE];
int32_t main()
{
srand( time(NULL) );
printf("generating PRN array[%i], range: %i\n", COUNT, RND_RANGE);
for( int32_t i = 0; i < COUNT; i++ )
{
ip[i] = rand() % RND_RANGE;
}
memset(op, 0, sizeof(op) );
printf("sorting PRN array...\n");
for( int32_t i = 0; i < COUNT; i++ )
{
op[ ip[i] ]++;
}
#ifdef OUTPUT
printf("output: \n");
for( int32_t i = 0; i < RND_RANGE; i++ )
{
if (op[i] > 0) printf("%i(%i)\t", i, op[i] );
}
#endif // OUTPUT
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment