nbench0.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,045 行 · 第 1/3 页
C
1,045 行
/*
** nbench0.c
*/
/*******************************************
** BYTEmark (tm) **
** BYTE MAGAZINE'S NATIVE MODE BENCHMARKS **
** FOR CPU/FPU **
** ver 2.0 **
** Rick Grehan, BYTE Magazine **
********************************************
** NOTE: These benchmarks do NOT check for the presence
** of an FPU. You have to find that out manually.
**
** REVISION HISTORY FOR BENCHMARKS
** 9/94 -- First beta. --RG
** 12/94 -- Bug discovered in some of the integer routines
** (IDEA, Huffman,...). Routines were not accurately counting
** the number of loops. Fixed. --RG (Thanks to Steve A.)
** 12/94 -- Added routines to calculate and display index
** values. Indexes based on DELL XPS 90 (90 MHz Pentium).
** 1/95 -- Added Mac time manager routines for more accurate
** timing on Macintosh (said to be good to 20 usecs) -- RG
** 1/95 -- Re-did all the #defines so they made more
** sense. See NMGLOBAL.H -- RG
** 3/95 -- Fixed memory leak in LU decomposition. Did not
** invalidate previous results, just made it easier to run.--RG
** 3/95 -- Added TOOLHELP.DLL timing routine to Windows timer. --RG
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "nmglobal.h"
#include "nbench0.h"
#include "report.h"
static double CurrTime;
static double TotalTime;
/*************
**** main ****
*************/
#ifdef MAC
void main(void)
#else
void main(int argc, char **argv)
#endif
{
int i; /* Index */
time_t time_and_date; /* Self-explanatory */
struct tm *loctime;
double bmean; /* Benchmark mean */
double bstdev; /* Benchmark stdev */
double intindex; /* Integer index */
double fpindex; /* Floating-point index */
ulong bnumrun; /* # of runs */
#ifdef MAC
MaxApplZone();
#endif
#ifdef MACTIMEMGR
/* Set up high res timer */
MacHSTdelay=600*1000*1000; /* Delay is 10 minutes */
memset((char *)&myTMTask,0,sizeof(TMTask));
/* Prime and remove the task, calculating overhead */
PrimeTime((QElemPtr)&myTMTask,-MacHSTdelay);
RmvTime((QElemPtr)&myTMTask);
MacHSTohead=MacHSTdelay+myTMTask.tmCount;
#endif
#ifdef WIN31TIMER
/* Set up the size of the timer info structure */
win31tinfo.dwSize=(DWORD)sizeof(TIMERINFO);
/* Load library */
if((hThlp=LoadLibrary("TOOLHELP.DLL"))<32)
{ printf("Error loading TOOLHELP\n");
exit(0);
}
if(!(lpfn=GetProcAddress(hThlp,"TimerCount")))
{ printf("TOOLHELP error\n");
exit(0);
}
#endif
/*
** Set global parameters to default.
*/
global_min_ticks=MINIMUM_TICKS;
global_min_seconds=MINIMUM_SECONDS;
global_allstats=0;
global_custrun=0;
write_to_file=0;
intindex=(double)1.0;
fpindex=(double)1.0;
/*
** We presume all tests will be run unless told
** otherwise
*/
for(i=0;i<NUMTESTS;i++)
tests_to_do[i]=1;
/*
** Initialize test data structures to default
** values.
*/
set_request_secs(); /* Set all request_secs fields */
global_numsortstruct.adjust=0;
global_numsortstruct.arraysize=NUMARRAYSIZE;
global_strsortstruct.adjust=0;
global_strsortstruct.arraysize=STRINGARRAYSIZE;
global_bitopstruct.adjust=0;
global_bitopstruct.bitfieldarraysize=BITFARRAYSIZE;
global_emfloatstruct.adjust=0;
global_emfloatstruct.arraysize=EMFARRAYSIZE;
global_fourierstruct.adjust=0;
global_assignstruct.adjust=0;
global_ideastruct.adjust=0;
global_ideastruct.arraysize=IDEAARRAYSIZE;
global_huffstruct.adjust=0;
global_huffstruct.arraysize=HUFFARRAYSIZE;
global_nnetstruct.adjust=0;
global_lustruct.adjust=0;
/*
** For Macintosh -- read the command line.
*/
#ifdef MAC
UCommandLine();
#endif
/*
** Handle any command-line arguments.
*/
if(argc>1)
for(i=1;i<argc;i++)
if(parse_arg(argv[i])==-1)
{ display_help(argv[0]);
exit(0);
}
/*
** Output header
*/
output_string("BBBBBB YYY Y TTTTTTT EEEEEEE\n");
output_string("BBB B YYY Y TTT EEE\n");
output_string("BBB B YYY Y TTT EEE\n");
output_string("BBBBBB YYY Y TTT EEEEEEE\n");
output_string("BBB B YYY TTT EEE\n");
output_string("BBB B YYY TTT EEE\n");
output_string("BBBBBB YYY TTT EEEEEEE\n\n");
output_string("BYTEmark (tm) Native Mode Benchmark ver. 2 (3/95)\n");
/*
** See if the user wants all stats. Output heading info
** if so.
*/
if(global_allstats)
{
output_string("========== ALL STATISTICS ==========\n");
time(&time_and_date);
loctime=localtime(&time_and_date);
sprintf(buffer,"**%s",asctime(loctime));
output_string(buffer);
sprintf(buffer,"**%s\n",sysname);
output_string(buffer);
sprintf(buffer,"**%s\n",compilername);
output_string(buffer);
sprintf(buffer,"**%s\n",compilerversion);
output_string(buffer);
sprintf(buffer,"**Sizeof: int:%u short:%u long:%u\n",
(unsigned int)sizeof(int),
(unsigned int)sizeof(short),
(unsigned int)sizeof(long));
output_string(buffer);
output_string("====================================\n");
}
/*
** Execute the tests.
*/
for(i=0;i<NUMTESTS;i++)
{
if(tests_to_do[i])
{ sprintf(buffer,"%s:",ftestnames[i]);
output_string(buffer);
bench_with_confidence(i,
&bmean,
&bstdev,
&bnumrun);
sprintf(buffer, "Bmark(%s)", ftestnames[i] );
Report( buffer, TotalTime );
sprintf(buffer," Iterations/sec.: %lf Index: %lf\n",
bmean,bmean/bindex[i]);
output_string(buffer);
/*
** Gather integer or FP indexes
*/
if((i==4)||(i==8)||(i==9))
/* FP index */
fpindex=fpindex*(bmean/bindex[i]);
else
/* Integer index */
intindex=intindex*(bmean/bindex[i]);
if(global_allstats)
{
sprintf(buffer," Standard Deviation: %lf\n Number of runs: %lu\n",
bstdev,bnumrun);
output_string(buffer);
show_stats(i);
}
}
}
printf("...done...\n");
/*
** Output the total indexes
*/
if(global_custrun==0)
{
output_string("===========OVERALL============\n");
sprintf(buffer,"INTEGER INDEX: %lf\nFLOATING-POINT INDEX: %lf\n",pow(intindex,(double).142857),
pow(fpindex,(double).33333));
output_string(buffer);
output_string(" (90 MHz Dell Pentium = 1.00)\n");
output_string("==============================\n");
}
exit(0);
}
void ReportTime( double cur_time ) {
CurrTime = cur_time;
}
/**************
** parse_arg **
***************
** Given a pointer to a string, we assume that's an argument.
** Parse that argument and act accordingly.
** Return 0 if ok, else return -1.
*/
static int parse_arg(char *argptr)
{
int i; /* Index */
FILE *cfile; /* Command file identifier */
/*
** First character has got to be a hyphen.
*/
if(*argptr++!='-') return(-1);
/*
** Convert the rest of the argument to upper case
** so there's little chance of confusion.
*/
for(i=0;i<strlen(argptr);i++)
argptr[i]=(char)toupper((int)argptr[i]);
/*
** Next character picks the action.
*/
switch(*argptr++)
{
case '?': return(-1); /* Will display help */
case 'C': /* Command file name */
/*
** First try to open the file for reading.
*/
cfile=fopen(argptr,"r");
if(cfile==(FILE *)NULL)
{ printf("**Error opening file: %s\n",argptr);
return(-1);
}
read_comfile(cfile); /* Read commands */
fclose(cfile);
break;
default:
return(-1);
}
return(0);
}
/*******************
** display_help() **
********************
** Display a help message showing argument requirements and such.
** Exit when you're done...I mean, REALLY exit.
*/
void display_help(char *progname)
{
printf("Usage: %s [-c<FILE>]\n",progname);
printf(" -c = Input parameters thru command file <FILE>\n");
exit(0);
}
/*****************
** read_comfile **
******************
** Read the command file. Set global parameters as
** specified. This routine assumes that the command file
** is already open.
*/
static void read_comfile(FILE *cfile)
{
char inbuf[40];
char *eptr; /* Offset to "=" sign */
int i; /* Index */
/*
** Sit in a big loop, reading a line from the file at each
** pass. Terminate on EOF.
*/
while(fgets(inbuf,39,cfile)!=(char *)NULL)
{
/* Overwrite the CR character */
if(strlen(inbuf)>0)
inbuf[strlen(inbuf)-1]='\0';
/*
** Parse up to the "=" sign. If we don't find an
** "=", then flag an error.
*/
if((eptr=strchr(inbuf,(int)'='))==(char *)NULL)
{ printf("**COMMAND FILE ERROR at LINE:\n %s\n",
inbuf);
goto skipswitch; /* A GOTO!!!! */
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?