home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
ddjmag
/
ddj8908.arc
/
LADD.LST
< prev
next >
Wrap
File List
|
1989-07-06
|
16KB
|
781 lines
BENCHMARKING TURBO C AND QUICKC
by Scott Robert Ladd
[GRIND.C]
/*
Program: Grind
Version: 1.11
Date: 26-Oct-1988
Language: ANSI C
Tests all aspects of a C compiler's functions, including disk i/o,
screen i/o, floating point, recursion, prototyping, and memory
allocation. It should be a large enough program to test the advanced
optimizers in some compilers.
Developed by Scott Robert Ladd. This program is public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAXFLOATS 1000
struct tabent
{
double val, vsum, vsqr, vcalc;
};
struct tabent table[MAXFLOATS];
char *errmsg[] = {
"GRIND.TBL cannot be created",
"GRIND.TBL cannot be closed properly",
"GRIND.IN cannot be found",
"GRIND.IN has been truncated",
"GRIND.IN cannot be closed properly"
};
/* function prototypes */
short main(void);
void readfloats(void);
void sortfloats(void);
void quicksort(struct tabent *, short, short);
void maketable(void);
void writetable(void);
void error(short);
short main(void)
{
puts("\nGrind (C) v1.10 -- A Benchmark Program\n");
readfloats();
sortfloats();
maketable();
writetable();
puts("\7End run GRIND!!!");
return(0);
}
void readfloats()
{
register short i;
char buf[12];
FILE *fltsin;
printf("--> Reading in floats. At # ");
if (NULL == (fltsin = fopen("GRIND.IN","r")))
error(2);
for (i = 0; i < MAXFLOATS; ++i)
{
printf("\b\b\b\b\b%5d",i);
if (NULL == fgets(buf,12,fltsin))
error(3);
table[i].val = atof(buf);
}
if (fclose(fltsin))
error(4);
printf("\n");
}
void sortfloats()
{
puts("--> Sorting data");
quicksort(table,0,MAXFLOATS-1);
}
void quicksort(struct tabent * item,
short left,
short right)
{
register short i, j;
struct tabent x, y;
i = left;
j = right;
x = item[(i+j)/2];
do
{
while (item[i].val < x.val && i < right) i++;
while (x.val < item[j].val && j > left) j--;
if (i <= j)
{
y = item[i];
item[i] = item[j];
item[j] = y;
i++;
j--;
}
}
while (i <= j);
if (left < j) quicksort(item,left,j);
if (i < right) quicksort(item,i,right);
}
void maketable()
{
register short i;
double sum = 0.0;
puts("--> Calculating table values");
for (i = 0; i < MAXFLOATS; ++i)
{
sum = sum + table[i].val;
table[i].vsum = sum;
table[i].vsqr = table[i].val * table[i].val;
table[i].vcalc = sqrt(fabs(table[i].val)) * log10(fabs(table[i].val));
}
}
void writetable()
{
FILE *fd;
register short i;
if (NULL == (fd = fopen("GRIND.TBL","w+")))
error(0);
puts("--> Writing Table to File");
for (i = 0; i < MAXFLOATS; i = i + 10)
{
fprintf(fd,
"val = %5.2f, sum = %5.2f, sqr = %5.2f, calc = %5.2f\n",
table[i].val,
table[i].vsum,
table[i].vsqr,
table[i].vcalc);
}
if (fclose(fd))
error(1);
}
void error(short err_no)
{
printf("\n\7GRIND ERROR: %s\n",errmsg[err_no]);
exit(err_no);
}
[DMATH.C]
/*
Benchmark: DMath
Version: 1.00 23-Jan-1989
Language: ANSI C
Computes all of the sines of the angles between 0 and 360 degrees using
doubles.
Developed by Scott Robert Ladd. This program is public domain.
*/
#define dabs(a) (((a) < 0.0) ? (-(a)) : (a))
/* conversion factor for converting radian to degrees */
#define deg2rad 57.29577951
/* prototypes */
void main(void);
double fact(double);
double power(double, double);
void main()
{
double angle, radians, sine, worksine, temp, k;
for (angle = 0.0; angle <= 360.0; angle += 1.0)
{
radians = angle / deg2rad;
k = 0.0;
worksine = 0.0;
do {
sine = worksine;
temp = (2.0 * k) + 1.0;
worksine += (power(-1.0,k) / fact(temp)) * power(radians,temp);
k += 1.0;
}
while (dabs(sine - worksine) > 1E-8);
}
}
/* Note: this function is designed for speed; it ONLY works when n is integral */
double fact(double n)
{
double res;
res = 1.0;
while (n > 0.0)
{
res *= n;
n -= 1.0;
}
return res;
}
/* Note: this function is designed for speed; it ONLY works when p is integral */
double power(double n, double p)
{
double res;
res = 1.0;
while (p > 0.0)
{
res *= n;
p -= 1.0;
}
return res;
}
[FXREF.C]
/*
Program: FXREF (File Cross-Reference)
Version: 1.10
Date: 21-Sep-1988
Language: ANSI C
Reads a file from standard input, and sorts and organizes each
token (word) found using a binary tree, keeping track of the number
of occurences of each token and their location by line and column.
It then prints a report to stdout.
Released into the public domain for "educational" purposes.
*/
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "stdlib.h"
/* type definitions */
typedef unsigned short line_no;
typedef struct loc_s
{
line_no line;
struct loc_s * next;
}
location;
typedef struct tok_s
{
struct tok_s * less, * more;
char * text;
struct loc_s *loc, *last;
}
token;
token * root;
char * err_msg[] = {
"token table root",
"token text",
"location references",
"token record"
};
/* function prototypes */
int main(void);
void parse_tokens(char *, line_no);
void add_tree(char *, line_no);
token * find_tree(char *);
void show_tree(token *);
void error(short);
int main()
{
char buf[256];
line_no line=0;
if (NULL == (root = ( token *)malloc(sizeof( token))))
error(0);
root->less = NULL;
root->more = NULL;
root->text = NULL;
root->loc = NULL;
while (NULL != (fgets(buf,256,stdin)))
{
++line;
printf("%5u: %s",line,buf);
parse_tokens(buf,line);
}
printf("\x0C\n");
show_tree(root);
return 0;
}
void parse_tokens(char * buf, line_no line)
{
char tok[256];
line_no pos;
while (1)
{
while ((!isalpha(*buf)) && (*buf != 0))
++buf;
if (*buf == 0)
return;
pos = 0;
while (isalpha(*buf))
tok[pos++] = *buf++;
tok[pos] = 0;
add_tree(tok,line);
}
}
void add_tree(char * tok, line_no line)
{
token *temp_tok, *new_tok;
location *temp_loc;
short comp;
if (root->text == NULL)
{
if (NULL == (root->text = (char *)malloc((unsigned)strlen(tok)+1)))
error(1);
strcpy(root->text,tok);
if (NULL == (root->loc = ( location *)malloc(sizeof( location))))
error(2);
root->loc->line = line;
root->loc->next = NULL;
root->last = root->loc;
return;
}
temp_tok = find_tree(tok);
if (comp = strcmp(tok,temp_tok->text))
/* comp is true (non-zero) if they don't match */
{
if (NULL == (new_tok = ( token *)malloc(sizeof( token))))
error(3);
if (NULL == (new_tok->text = (char *)malloc((unsigned)strlen(tok)+1)))
error(1);
new_tok->less = NULL;
new_tok->more = NULL;
strcpy(new_tok->text,tok);
if (NULL == (new_tok->loc = ( location *)malloc(sizeof( location))))
error(2);
new_tok->loc->line = line;
new_tok->loc->next = NULL;
new_tok->last = new_tok->loc;
if (comp < 0)
temp_tok->less = new_tok;
else
temp_tok->more = new_tok;
}
else
/* if comp is false (0), the tokens match */
{
if (NULL == (temp_loc = ( location *)malloc(sizeof( location))))
error(2);
temp_loc->line = line;
temp_loc->next = NULL;
temp_tok->last->next = temp_loc;
temp_tok->last = temp_loc;
}
}
token *find_tree(char * tok)
{
short comp;
token *node;
node = root;
while (1)
{
if (0 == (comp = strcmp(tok,node->text)))
return node;
if (comp < 0)
if (node->less == NULL)
return node;
else
node = node->less;
else
if (node->more == NULL)
return node;
else
node = node->more;
}
}
void show_tree(token * node)
{
location *lloc;
short pos;
if (NULL == node) return;
show_tree(node->less);
printf("%-32s: ",node->text);
pos = -1;
lloc = node->loc;
while (lloc != NULL)
{
if (++pos == 7)
{
pos = 0;
printf("\n%32s: "," ");
}
printf("%5d ",lloc->line);
lloc = lloc->next;
}
printf("\n");
show_tree(node->more);
}
void error(short err_no)
{
printf("\nFXREF ERROR: Cannot allocate space for %s\n",err_msg[err_no]);
exit(err_no+1);
}
[GRAPH_QC.C]
/*
Benchmark: GRAPH_QC
Version: 1.00 29-Jan-1989
Language: Microsoft QuickC v2.00
Purpose: Tests the speed of QuickC's graphics functions.
Written by Scott Robert Ladd. Released into the public domain.
*/
#include "time.h"
#include "stdio.h"
#include "graph.h"
#include "stddef.h"
short main(void);
void initialize(void);
void draw_lines(void);
void draw_ellipses(void);
void draw_and_fill(void);
void finalize(void);
short max_x, max_y;
short mid_x, mid_y;
struct videoconfig scrn_cfg ;
clock_t start;
float line_time, ellipse_time, fill_time;
short main()
{
initialize();
draw_lines();
draw_ellipses();
draw_and_fill();
finalize();
return 0;
}
void initialize()
{
_setvideomode(_ERESCOLOR);
_getvideoconfig(&scrn_cfg);
max_x = scrn_cfg.numxpixels - 1;
max_y = scrn_cfg.numypixels - 1;
mid_x = max_x / 2;
mid_y = max_y / 2;
}
void draw_lines()
{
short i, x, y;
start = clock();
for (i = 0; i <= 5; ++i)
{
if ((i % 2) == 0)
_setcolor(_BRIGHTWHITE);
else
_setcolor(_BLACK);
for (x = 0; x <= max_x; x += 4)
{
_moveto(x,0);
_lineto(max_x - x,max_y);
}
for (y = 0; y <= max_y; y += 2)
{
_moveto(max_x,y);
_lineto(0,max_y - y);
}
}
line_time = (clock() - start) / CLK_TCK;
_clearscreen(_GCLEARSCREEN);
}
void draw_ellipses()
{
short x, y;
_setcolor(_BRIGHTWHITE);
start = clock();
for (x = 6; x < mid_x; x += 6)
for (y = 10; y < mid_y; y += 10)
_ellipse(_GBORDER, mid_x - x, mid_y - y, mid_x + x, mid_y + y);
ellipse_time = (clock() - start) / CLK_TCK;
_clearscreen(_GCLEARSCREEN);
}
void draw_and_fill()
{
short i, color;
_moveto(0,0);
_lineto(20,0);
_lineto(30,20);
_lineto(10,40);
_lineto(10,50);
_lineto(100,50);
_lineto(100,52);
_lineto(50,52);
_lineto(50,54);
_lineto(102,54);
_lineto(102,10);
_lineto(630,120);
_lineto(500,150);
_lineto(620,180);
_lineto(510,200);
_lineto(630,250);
_lineto(400,340);
_lineto(5,300);
_lineto(0,0);
_setfillmask(NULL);
start = clock();
for (i = 0; i < 4; ++i)
{
for (color = 1; color < 15; ++color)
{
_setcolor(color);
_floodfill(mid_x, mid_y, _BRIGHTWHITE);
}
}
fill_time = (clock() - start) / CLK_TCK;
_clearscreen(_GCLEARSCREEN);
}
void finalize()
{
_setvideomode(_DEFAULTMODE);
printf("line time = %.1f\n",line_time);
printf("ellipse time = %.1f\n",ellipse_time);
printf("fill time = %.1f\n",fill_time);
}
[GRAPH_TC.C]
/*
Benchmark: GRAPH_TC
Version: 1.00 29-Jan-1989
Language: Borland Turbo C v2.0
Purpose: Tests the speed of QuickC's graphics functions.
Written by Scott Robert Ladd. Released into the public domain.
*/
#include "time.h"
#include "stdio.h"
#include "graphics.h"
short main(void);
void initialize(void);
void draw_lines(void);
void draw_ellipses(void);
void draw_and_fill(void);
void finalize(void);
short max_x, max_y;
short mid_x, mid_y;
clock_t start;
float line_time, ellipse_time, fill_time;
int driver = EGA,
mode = EGAHI;
short main()
{
initialize();
draw_lines();
draw_ellipses();
draw_and_fill();
finalize();
return 0;
}
void initialize()
{
initgraph(&driver, &mode, "D:\\TC\\BGI");
max_x = 639;
max_y = 349;
mid_x = max_x / 2;
mid_y = max_y / 2;
}
void draw_lines()
{
short i, x, y;
start = clock();
for (i = 0; i <= 5; ++i)
{
if ((i % 2) == 0)
setcolor(WHITE);
else
setcolor(BLACK);
for (x = 0; x <= max_x; x += 4)
{
moveto(x,0);
lineto(max_x - x,max_y);
}
for (y = 0; y <= max_y; y += 2)
{
moveto(max_x,y);
lineto(0,max_y - y);
}
}
line_time = (clock() - start) / CLK_TCK;
cleardevice();
}
void draw_ellipses()
{
short x, y;
setcolor(WHITE);
start = clock();
for (x = 6; x < mid_x; x += 6)
for (y = 10; y < mid_y; y += 10)
ellipse(mid_x, mid_y, 0, 360, x, y);
ellipse_time = (clock() - start) / CLK_TCK;
cleardevice();
}
void draw_and_fill()
{
short i, color;
moveto(0,0);
lineto(20,0);
lineto(30,20);
lineto(10,40);
lineto(10,50);
lineto(100,50);
lineto(100,52);
lineto(50,52);
lineto(50,54);
lineto(102,54);
lineto(102,10);
lineto(630,120);
lineto(500,150);
lineto(620,180);
lineto(510,200);
lineto(630,250);
lineto(400,340);
lineto(5,300);
lineto(0,0);
start = clock();
for (i = 0; i < 4; ++i)
{
for (color = 1; color < 15; ++color)
{
setfillstyle(SOLID_FILL,color);
floodfill(mid_x, mid_y, WHITE);
}
}
fill_time = (clock() - start) / CLK_TCK;
cleardevice();
}
void finalize()
{
closegraph();
printf("line time = %.1f\n",line_time);
printf("ellipse time = %.1f\n",ellipse_time);
printf("fill time = %.1f\n",fill_time);
}