小标
2018-10-10
来源 :
阅读 2250
评论 0
摘要:本文主要向大家介绍了C/C++知识点之纯C语言跑分(详细注释),通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。
本文主要向大家介绍了C/C++知识点之纯C语言跑分(详细注释),通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。
#include
#include
const int N_qsort=10000;//快排的数据规模
const int M=20000,N=50000;//整点、浮点运算的规模
const int N_pi=100000000;//计算圆周率的运算规模
double s_int,s_float,s_pi,s_sort;
void int_comp(void);//整点运算
void float_comp(void);//浮点运算
void pi_comp(void);//泰勒级数推论式计算圆周率
void Qsort(int a[],int low,int high);//快排算法
void qsort(void);//调用快排算法的函数
void panduan();
void PAUSE();
int main(){
printf("------\n性能测试开始\n");
int_comp();//整点运算
float_comp();//浮点运算
pi_comp();//泰勒级数推论式计算圆周率
qsort();//快速排序
printf("------\n测试结束\n");
printf("整点运算得分:%lf\n",s_int);
printf("泰勒级数推论式计算圆周率运算得分:%lf\n",s_pi);
printf("排序运算得分:%lf\n",s_sort);
printf("总得分:%lf\n",s_int+s_float+s_pi+s_sort);
panduan();
PAUSE();
}
void int_comp(void){//整点加法
printf("整点运算测试中(运算次数为:%lf)\n",(double)M*N);
clock_t start,end;
int i,j;
start=clock();
for(i=0;i<M;i++)
for(j=0;j<N;j++);
end=clock();
double duration=(double)(end-start)/CLOCKS_PER_SEC;
double score=(M*N)/duration;
/*注:score本身即为运算速度,数量级一般在亿,为方便起见,本程序的分数均采用运算速度除以一万后的结果!除特殊说明,后面类同!*/
s_int=score/10000;
//printf("整点运算测试完毕!分数:%lf\n",s_int);
}
void float_comp(void){//浮点加法
printf("浮点运算测试中(运算次数为:%lf)\n",(double)M*N);
clock_t start,end;
float i,j;
start=clock();
for(i=0;i<M;i++)
for(j=0;j<N;j++);
end=clock();
double duration=(double)(end-start)/CLOCKS_PER_SEC;
double score=(M*N)/duration;
s_float=score/10000;
//printf("浮点运算测试完毕!分数:%lf\n",s_float);
}
void pi_comp(void){
printf("泰勒级数推论式计算圆周率中(运算次数为:%d)\n",N_pi);
int m,i=1;
double s=0;
clock_t start,end;
start=clock();
for(m=1;m<N_pi;m+=2){
s+=i*(1.0/m);
i=-i;
}
end=clock();
double duration=(double)(end-start)/CLOCKS_PER_SEC;
double score=N_pi/duration;
//下面一行可输出计算出来的圆周率
printf("pi=%lf\n",4*s);
s_pi=score/10000;
//printf("泰勒级数推论式计算圆周率完毕!分数:%lf\n",s_pi);
}
void Qsort(int a[],int low,int high){//快排算法
if(low>=high) return;
int first=low;
int last=high;
int key=a[first];
while(first<last){
while(first
a[first]=a[last];
while(first<last&&a[first]<=key) ++first;
a[last]=a[first];
}
a[first]=key;
Qsort(a,low,first-1);
Qsort(a,first+1,high);
}
void qsort(void){//调用快排算法的函数
int a[N_qsort],i;
for(i=N_qsort;i>0;i--) a[N_qsort-1]=i;
printf("排序运算中(对%d个数进行快速排序)\n",N_qsort);//采用最坏时间方案
clock_t start,end;
start=clock();
Qsort(a,0,N_qsort-1);
end=clock();
double duration=(double)(end-start)/CLOCKS_PER_SEC;
double score=(N_qsort*N_qsort)/duration;
s_sort=score/10000;
//printf("排序运算测试完毕!分数:%lf\n",s_sort);
}
void panduan(){
float i=s_int+s_float+s_pi+s_sort;
printf("根据分数,授予您的爱机<");
if (i>0&&i<20000){
printf("渣渣");
}
else if (i>20000&&i<30000){
printf("低端");
}
else if (i>30000&&i<40000){
printf("中端");
}
else if (i>40000&&i<50000){
printf("高端");
}
else if (i>50000&&i<60000){
printf("超高端");
}
else if (i>60000){
printf("机皇");
}
printf(">称号\n");
}
void PAUSE(){
clean_stdin();
}
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言C/C+频道!
喜欢 | 1
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号