Last active
August 13, 2017 15:21
-
-
Save realModusOperandi/18be449829ffa9317089fbd804fb8da8 to your computer and use it in GitHub Desktop.
Byte Macintosh C Compiler Benchmark, Corrected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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