cpu性能测试代码

原文:http://tieba.baidu.com/p/3203920933

#include<time.h>

#include<stdio.h>
#include<math.h>
#include <sys/time.h>
#include<stdlib.h>

#define STEPS 5000000

long per[5],s[5];
int a,b,k,u,v,w,m,n;
long int_per[5];
void interger()
{
    int i;
    long f=1;
    for(m=1;m<2000000;m++)
    {
        n=100;
        for(i=1;i<n;i++)
        {
            f=f*i;
        }
    }
}
void function()
{
    int i,k=0;
    double p=2;
    for (i=0;i<STEPS;i++)
    {
        p*=((double)(((int)((i+2)/2))*2))/(((int)((i+1)/2))*2+1);
    }
}

void compute()
{
    struct timeval tpstart,tpend;
    float timeuse;
    printf("\033[4A\033[18D\033[?25l\033[36;5m欢迎您使用CPU Test (CPU性能测试)!\033[0m\n\n正在为您的手机进行\033[32;5mCPU浮点运算性能\033[0m测试……\n请尽量避免其他操作!\n\033[32;5m当前测试进度%d%%……\033[0m",k*10+10);
    gettimeofday(&tpstart,NULL);
    function();
    gettimeofday(&tpend,NULL);
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+
    tpend.tv_usec-tpstart.tv_usec;
    timeuse/=1000000;
    a=STEPS/timeuse;
    b=a/10000;
}

void compute_interger()
{
    struct timeval tpstart,tpend;
    float timeuse;
    printf("\033[2A\033[18D\033[?25l正在为您的手机进行\033[32;5mCPU整形运算性能\033[0m测试……\n请尽量避免其他操作!\n\033[32;5m当前测试进度%d%%……\033[0m",k*10);
    gettimeofday(&tpstart,NULL);
    interger();
    gettimeofday(&tpend,NULL);
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+
    tpend.tv_usec-tpstart.tv_usec;
    timeuse/=1000000;
    u=m/timeuse;
    v=u/10000;
}

int main()
{
    int x,soccer,soccer1,int_soccer,result;
    for (k=0;k<5;k++)
    {
        compute();
        per[k]=b;
        s[k]=a;
    }
    int int_x;
    for (k=6;k<11;k++)
    {
        compute_interger();
        int_per[k]=v;
    }
    x=(per[1]+per[2]+per[3]+per[4])/4;
    soccer1=(s[1]+s[2]+s[3]+s[4])/4;
    soccer=soccer1*0.001197;
    int_x=(int_per[6]+int_per[7]+int_per[8]+int_per[9]+int_per[10])/5;
    int_soccer=int_x*17.56946;
    result=soccer+int_soccer;
    system("clear");

    printf("\033[32;5m\n测试完成!\033[0m\n\n您的CPU性能测试分数是:\033[36;5m%d\033[0m!\n\n浮点运算得分为:\033[36;5m%d\033[0m!\n整数运算得分为:\033[5m\033[36m%d\033[0m!\n\n\n\nBy:\033[35;5m风雪梧桐\033[0m\n\n",result,soccer,int_soccer);
}


  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值