nbench0.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,045 行 · 第 1/3 页
C
1,045 行
/*
** Insert a null where the "=" was, then convert
** the substring to uppercase. That will enable
** us to perform the match.
*/
*eptr++='\0';
strtoupper((char *)&inbuf[0]);
i=MAXPARAM;
do {
if(strcmp(inbuf,paramnames[i])==0)
break;
} while(--i>=0);
if(i<0)
{ printf("**COMMAND FILE ERROR -- UNKNOWN PARAM: %s",
inbuf);
goto skipswitch;
}
/*
** Advance eptr to the next field...which should be
** the value assigned to the parameter.
*/
switch(i)
{
case PF_GMTICKS: /* GLOBALMINTICKS */
global_min_ticks=(ulong)atol(eptr);
break;
case PF_MINSECONDS: /* MINSECONDS */
global_min_seconds=(ulong)atol(eptr);
set_request_secs();
break;
case PF_ALLSTATS: /* ALLSTATS */
global_allstats=getflag(eptr);
break;
case PF_OUTFILE: /* OUTFILE */
strcpy(global_ofile_name,eptr);
global_ofile=fopen(global_ofile_name,"a");
/*
** Open the output file.
*/
if(global_ofile==(FILE *)NULL)
{ printf("**Error opening output file: %s\n",
global_ofile_name);
ErrorExit();
}
write_to_file=-1;
break;
case PF_CUSTOMRUN: /* CUSTOMRUN */
global_custrun=getflag(eptr);
for(i=0;i<NUMTESTS;i++)
tests_to_do[i]=1-global_custrun;
break;
case PF_DONUM: /* DONUMSORT */
tests_to_do[TF_NUMSORT]=getflag(eptr);
break;
case PF_NUMNUMA: /* NUMNUMARRAYS */
global_numsortstruct.numarrays=
(ushort)atoi(eptr);
global_numsortstruct.adjust=1;
break;
case PF_NUMASIZE: /* NUMARRAYSIZE */
global_numsortstruct.arraysize=
(ulong)atol(eptr);
break;
case PF_NUMMINS: /* NUMMINSECONDS */
global_numsortstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOSTR: /* DOSTRINGSORT */
tests_to_do[TF_SSORT]=getflag(eptr);
break;
case PF_STRASIZE: /* STRARRAYSIZE */
global_strsortstruct.arraysize=
(ulong)atol(eptr);
break;
case PF_NUMSTRA: /* NUMSTRARRAYS */
global_strsortstruct.numarrays=
(ushort)atoi(eptr);
global_strsortstruct.adjust=1;
break;
case PF_STRMINS: /* STRMINSECONDS */
global_strsortstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOBITF: /* DOBITFIELD */
tests_to_do[TF_BITOP]=getflag(eptr);
break;
case PF_NUMBITOPS: /* NUMBITOPS */
global_bitopstruct.bitoparraysize=
(ulong)atol(eptr);
global_bitopstruct.adjust=1;
break;
case PF_BITFSIZE: /* BITFIELDSIZE */
global_bitopstruct.bitfieldarraysize=
(ulong)atol(eptr);
break;
case PF_BITMINS: /* BITMINSECONDS */
global_bitopstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOEMF: /* DOEMF */
tests_to_do[TF_FPEMU]=getflag(eptr);
break;
case PF_EMFASIZE: /* EMFARRAYSIZE */
global_emfloatstruct.arraysize=
(ulong)atol(eptr);
break;
case PF_EMFLOOPS: /* EMFLOOPS */
global_emfloatstruct.loops=
(ulong)atol(eptr);
break;
case PF_EMFMINS: /* EMFMINSECOND */
global_emfloatstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOFOUR: /* DOFOUR */
tests_to_do[TF_FFPU]=getflag(eptr);
break;
case PF_FOURASIZE: /* FOURASIZE */
global_fourierstruct.arraysize=
(ulong)atol(eptr);
global_fourierstruct.adjust=1;
break;
case PF_FOURMINS: /* FOURMINSECONDS */
global_fourierstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOASSIGN: /* DOASSIGN */
tests_to_do[TF_ASSIGN]=getflag(eptr);
break;
case PF_AARRAYS: /* ASSIGNARRAYS */
global_assignstruct.numarrays=
(ulong)atol(eptr);
break;
case PF_ASSIGNMINS: /* ASSIGNMINSECONDS */
global_assignstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOIDEA: /* DOIDEA */
tests_to_do[TF_IDEA]=getflag(eptr);
break;
case PF_IDEAASIZE: /* IDEAARRAYSIZE */
global_ideastruct.arraysize=
(ulong)atol(eptr);
break;
case PF_IDEALOOPS: /* IDEALOOPS */
global_ideastruct.loops=
(ulong)atol(eptr);
break;
case PF_IDEAMINS: /* IDEAMINSECONDS */
global_ideastruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOHUFF: /* DOHUFF */
tests_to_do[TF_HUFF]=getflag(eptr);
break;
case PF_HUFFASIZE: /* HUFFARRAYSIZE */
global_huffstruct.arraysize=
(ulong)atol(eptr);
break;
case PF_HUFFLOOPS: /* HUFFLOOPS */
global_huffstruct.loops=
(ulong)atol(eptr);
global_huffstruct.adjust=1;
break;
case PF_HUFFMINS: /* HUFFMINSECONDS */
global_huffstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DONNET: /* DONNET */
tests_to_do[TF_NNET]=getflag(eptr);
break;
case PF_NNETLOOPS: /* NNETLOOPS */
global_nnetstruct.loops=
(ulong)atol(eptr);
global_nnetstruct.adjust=1;
break;
case PF_NNETMINS: /* NNETMINSECONDS */
global_nnetstruct.request_secs=
(ulong)atol(eptr);
break;
case PF_DOLU: /* DOLU */
tests_to_do[TF_LU]=getflag(eptr);
break;
case PF_LUNARRAYS: /* LUNUMARRAYS */
global_lustruct.numarrays=
(ulong)atol(eptr);
global_lustruct.adjust=1;
break;
case PF_LUMINS: /* LUMINSECONDS */
global_lustruct.request_secs=
(ulong)atol(eptr);
break;
}
skipswitch:
continue;
} /* End while */
return;
}
/************
** getflag **
*************
** Return 1 if cptr points to "T"; 0 otherwise.
*/
static int getflag(char *cptr)
{
if(toupper((int)*cptr)=='T') return(1);
return(0);
}
/***************
** strtoupper **
****************
** Convert's a string to upper case. The string is presumed
** to consist only of alphabetic characters, and to be terminated
** with a null.
*/
static void strtoupper(char *s)
{
do {
/*
** Oddly enough, the following line did not work under THINK C.
** So, I modified it....hmmmm. --RG
*s++=(char)toupper((int)*s);
*/
*s=(char)toupper((int)*s);
s++;
} while(*s!=(char)'\0');
return;
}
/*********************
** set_request_secs **
**********************
** Set everyone's "request_secs" entry to whatever
** value is in global_min_secs. This is done
** at the beginning, and possibly later if the
** user redefines global_min_secs in the command file.
*/
static void set_request_secs(void)
{
global_numsortstruct.request_secs=global_min_seconds;
global_strsortstruct.request_secs=global_min_seconds;
global_bitopstruct.request_secs=global_min_seconds;
global_emfloatstruct.request_secs=global_min_seconds;
global_fourierstruct.request_secs=global_min_seconds;
global_assignstruct.request_secs=global_min_seconds;
global_ideastruct.request_secs=global_min_seconds;
global_huffstruct.request_secs=global_min_seconds;
global_nnetstruct.request_secs=global_min_seconds;
global_lustruct.request_secs=global_min_seconds;
return;
}
/**************************
** bench_with_confidence **
***************************
** Given a benchmark id that indicates a function, this
** routine repeatedly calls that benchmark, seeking
** to collect enough scores to get 5 that meet the confidence
** criteria. Return 0 if ok, -1 if failure.
** Returns mean ans std. deviation of results if successful.
*/
static int bench_with_confidence(int fid, /* Function id */
double *mean, /* Mean of scores */
double *stdev, /* Standard deviation */
ulong *numtries) /* # of attempts */
{
double myscores[5]; /* Need at least 5 scores */
double c_half_interval; /* Confidence half interval */
int i; /* Index */
double newscore; /* For improving confidence interval */
/*
** Get first 5 scores. Then begin confidence testing.
*/
TotalTime = (double)0.0;
for (i=0;i<5;i++)
{ (*funcpointer[fid])();
myscores[i]=getscore(fid);
TotalTime += CurrTime;
}
*numtries=5; /* Show 5 attempts */
/*
** The system allows a maximum of 10 tries before it gives
** up. Since we've done 5 already, we'll allow 5 more.
*/
/*
** Enter loop to test for confidence criteria.
*/
while(1)
{
/*
** Calculate confidence.
*/
calc_confidence(myscores,
&c_half_interval,
mean,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?