[C语言]CPU跑分程序

news/2024/10/18 0:35:32/

|版权声明:本文为博主原创文章,未经博主允许不得转载。

Code:

  1 #include <stdio.h>
  2 #include <conio.h>
  3 #include <time.h>//clock()所属头文件
  4 const int N_qsort=10000;//快排的数据规模
  5 const int M=20000,N=50000;//整点、浮点运算的规模
  6 const int N_pi=100000000;//计算圆周率的运算规模
  7 double s_int,s_float,s_pi,s_sort;
  8 void int_comp(void);//整点运算
  9 void float_comp(void);//浮点运算
 10 void pi_comp(void);//泰勒级数推论式计算圆周率
 11 void Qsort(int a[],int low,int high);//快排算法
 12 void qsort(void);//调用快排算法的函数
 13 void panduan();
 14 void PAUSE();
 15 int main(){
 16      printf("------\n性能测试开始\n");
 17      int_comp();//整点运算
 18      float_comp();//浮点运算
 19      pi_comp();//泰勒级数推论式计算圆周率
 20      qsort();//快速排序
 21      printf("------\n测试结束\n");
 22      printf("整点运算得分:%lf\n",s_int);
 23      printf("泰勒级数推论式计算圆周率运算得分:%lf\n",s_pi);
 24      printf("排序运算得分:%lf\n",s_sort);
 25      printf("总得分:%lf\n",s_int+s_float+s_pi+s_sort);
 26      panduan();
 27      PAUSE();
 28      return 0;
 29 }
 30 
 31 void int_comp(void){//整点加法
 32      printf("整点运算测试中(运算次数为:%lf)\n",(double)M*N);
 33      clock_t start,end;
 34      int i,j;
 35      start=clock();
 36      for(i=0;i<M;i++)
 37          for(j=0;j<N;j++);
 38      end=clock();
 39      double duration=(double)(end-start)/CLOCKS_PER_SEC;
 40      double score=(M*N)/duration;
 41      /*注:score本身即为运算速度,数量级一般在亿,为方便起见,本程序的分数均采用运算速度除以一万后的结果!除特殊说明,后面类同!*/
 42      s_int=score/10000;
 43      //printf("整点运算测试完毕!分数:%lf\n",s_int);
 44 }
 45 
 46 void float_comp(void){//浮点加法
 47      printf("浮点运算测试中(运算次数为:%lf)\n",(double)M*N);
 48      clock_t start,end;
 49      float i,j;
 50      start=clock();
 51      for(i=0;i<M;i++)
 52      for(j=0;j<N;j++);
 53      end=clock();
 54      double duration=(double)(end-start)/CLOCKS_PER_SEC;
 55      double score=(M*N)/duration;
 56      s_float=score/10000;
 57      //printf("浮点运算测试完毕!分数:%lf\n",s_float);
 58 }
 59 
 60 void pi_comp(void){
 61      printf("泰勒级数推论式计算圆周率中(运算次数为:%d)\n",N_pi);
 62      int m,i=1;
 63      double s=0;
 64      clock_t start,end;
 65      start=clock();
 66      for(m=1;m<N_pi;m+=2){
 67         s+=i*(1.0/m);
 68         i=-i;
 69      }
 70      end=clock();
 71      double duration=(double)(end-start)/CLOCKS_PER_SEC;
 72      double score=N_pi/duration;
 73      //下面一行可输出计算出来的圆周率
 74      //printf("pi=%lf\n",4*s);
 75      s_pi=score/10000;
 76      //printf("泰勒级数推论式计算圆周率完毕!分数:%lf\n",s_pi);
 77 }
 78 void Qsort(int a[],int low,int high){//快排算法
 79      if(low>=high) return;
 80      int first=low;
 81      int last=high;
 82      int key=a[first];
 83      while(first<last){
 84          while(first<last&&a[last]>=key) --last;
 85          a[first]=a[last];
 86          while(first<last&&a[first]<=key) ++first;
 87          a[last]=a[first];
 88      }
 89      a[first]=key;
 90      Qsort(a,low,first-1);
 91      Qsort(a,first+1,high);
 92 }
 93 void qsort(void){//调用快排算法的函数
 94      int a[N_qsort],i;
 95      for(i=N_qsort;i>0;i--) a[N_qsort-1]=i;
 96      printf("排序运算中(对%d个数进行快速排序)\n",N_qsort);//采用最坏时间方案
 97      clock_t start,end;
 98      start=clock();
 99      Qsort(a,0,N_qsort-1);
100      end=clock();
101      double duration=(double)(end-start)/CLOCKS_PER_SEC;
102      double score=(N_qsort*N_qsort)/duration;
103      s_sort=score/10000;
104 //printf("排序运算测试完毕!分数:%lf\n",s_sort);
105 }
106 void panduan(){
107     float i=s_int+s_float+s_pi+s_sort;
108     printf("根据分数,授予您的爱机<");
109     if (i>0&&i<20000){
110         printf("渣渣");
111     }
112     else if (i>20000&&i<30000){
113         printf("低端");
114     }
115     else if (i>30000&&i<40000){
116         printf("中端");
117     }
118     else if (i>40000&&i<50000){
119         printf("高端");
120     }
121     else if (i>50000&&i<60000){
122         printf("超高端");
123     }
124     else if (i>60000){
125         printf("机皇");
126     }
127     printf(">称号\n");
128 }
129 void PAUSE(){
130     printf("\n请按任意键继续...");getch();fflush(stdin);
131 }

 

转载于:https://www.cnblogs.com/unixart/p/5965740.html


http://www.ppmy.cn/news/429063.html

相关文章

用Python实现一个CPU跑分程序

一般我们要对cpu进行跑分测试&#xff0c;在不同的系统有时测试软件不能统一&#xff0c;比如Linux下就没有CineBench&#xff0c;导致跑分成绩对比不方便&#xff0c;所以想着自己写一个简单的跑分程序。 代码用Python实现&#xff0c;可以分别进行单核和多核测试&#xff0c…

python获取某乎热搜数据并保存成Excel

python获取知乎热搜数据 一、获取目标、准备工作二、开始编码三、总结 一、获取目标、准备工作 1、获取目标&#xff1a; 本次获取教程目标&#xff1a;某乎热搜 2、准备工作 环境python3.xrequestspandas requests跟pandas为本次教程所需的库&#xff0c;requests用于模拟h…

模糊测试不“模糊”,高效发掘未知漏洞与 0day 攻击

近日&#xff0c;在「DevSecOps软件安全开发实践」课程上&#xff0c;极狐(GitLab) 高级测试工程师衡韬、极狐(GitLab) 高级后端开发工程师田鲁&#xff0c;分享了模糊测试的概念、必要性和在极狐GitLab 上的实践。 以下内容整理自本次直播&#xff0c;你也可以点击&#x1f44…

网络流量监控与分析软件

参考&#xff1a; https://www.cisco.com/c/en/us/products/ios-nx-os-software/ios-netflow/index.html https://zhuanlan.zhihu.com/p/87325697 ntopng&#xff0c;NetFlow、sFlow&#xff0c; NetFlow Analyzer

windows - 网络流量监控工具

由于需要在本地的流量监控工具 1、DUMeterPortable 可以对当前的pc网络的上下行做记录和统计&#xff0c;可以统计每天的流量控制&#xff0c;程序实时记录 2、BW 功能比较强大&#xff0c;但是监控比较烦人&#xff0c;如果是查看流量的话&#xff0c;这个软件没有必要 3、…

一款免费的网络流量实时监控软件

一款免费的网络流量实时监控软件 来源版块: 网络安全 压缩包内文件格式: 可执行文件 附件来源: 互联网 运行平台: Windows平台 是否经本人验证: 是 附件性质: 免费 详细说明: ySoft Network Monitor 是一款免费的网络流量实时监控软件&#xff0c;它能够将计算机上的各种网络…

软件实现局域网流量控制

有朋友问我怎样限制和他共享上网的其他人的带宽&#xff0c;我总是觉得这是不可能的&#xff0c;除非你有路由器的控制权&#xff0c;但是现在家用的低端路由器一般是没有流量控制的功能的。 根据本人凡事都百度的原则&#xff0c;我带着一线希望上网搜索了一下&#xff0c;发…

流量监控软件networx使用

1. 简介 Networx是一个用于流量监控与统计的工具&#xff0c;可以生成流量统计报表以及查看指定应用程序的流量情况。安装界面是英文的&#xff0c;安装后可以选择中文。下载地址&#xff1a;https://www.softperfect.com/download/ https://www.softperfect.com/download/ 2…