Skip to content

Instantly share code, notes, and snippets.

@realModusOperandi
Last active August 13, 2017 15: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 realModusOperandi/18be449829ffa9317089fbd804fb8da8 to your computer and use it in GitHub Desktop.
Save realModusOperandi/18be449829ffa9317089fbd804fb8da8 to your computer and use it in GitHub Desktop.
Byte Macintosh C Compiler Benchmark, Corrected
/* MINIMALLY UPDATED TO COMPILE UNDER LLVM. CHECK FIRST REVISION FOR UNEDITED VERSION */
/* sorting benchmark--calls randomly the number of times specified by MAXNUM
to create an array of long integers, then does a quicksort on the array of longs.
The program does this for the number of times specified by COUNT
*/
#include "stdio.h"
#define MAXNUM 100
#define COUNT 10
#define MODULUS ((long) 0x20000)
#define C 13849L
#define A 25173L
long seed = 7L;
long byterandom (long);
long buffer [MAXNUM] = {0};
main ()
{
int i, j;
long temp;
printf("Filling array and sorting %d times \n", COUNT);
for (i = 0; i < COUNT; ++i)
{
for (j = 0; j < MAXNUM; ++j) {
temp = byterandom (MODULUS);
if (temp < 0L)
temp = (-temp);
buffer[j] = temp;
}
printf("Buffer full, iteration %d\n", i);
}
quick (0, MAXNUM, buffer);
}
quick (lo, hi, base)
int lo, hi;
long base [];
{
int i, j;
long pivot, temp;
if (lo < hi)
{
for (i = lo, j = hi, pivot = base [hi]; i < j;)
{
while (i < hi && base [i] <= pivot)
++i;
while (j > lo && base [j] >= pivot)
--j;
if (i < j)
{
temp = base [i];
base [i] = base [j];
base [j] = temp;
}
}
temp = base [i];
base [i] = base [hi];
base [hi] = temp;
quick (lo, i - 1, base);
quick (i + 1, hi, base);
}
return 0;
}
long byterandom (size)
long size;
{
seed = seed * A + C;
return (seed % size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment