📄 test5.c
字号:
#include "stdio.h"
#include "time.h"
#include "math.h"
#include "inc.h"
#define MAX 30000
main()
{
int i;
unsigned long j;
clock_t start_time,end_time, during_time;
start_time = clock();
printf( "start_time=%d",start_time);
printf("\n");
/****************测试函数主体******************/
for(j=0; j<3000; j++)
{
/* Test_AddSub_Self(); */
/* Test_remain(); */
/* Test_equare1(); */
Test_equare2();
}
/**********************************************/
end_time = clock();
during_time= end_time - start_time;
printf("end_time=%d",end_time);
printf("\n\n");
printf("during_time=%d",during_time);
getch();
}
/******************************************************/
/*自加自减复合赋值表达式的效率比较*/
/******************************************************/
void Test_AddSub_Self()
{
int release;
int i, add=0;
for(i=0; i<MAX; i++)
{
add++;
/* add=add+1; */
}
}
/**********************************************************************************************/
/*减少运算强度*/
/**********************************************************************************************/
/*(只要是求2n方的余数,均可使用位操作的方法来代替)*/
void Test_remain()
{
int release;
int i, a;
for(i=0; i<MAX; i++)
{
a= 55;
a%=8;
/* a&=7;*/
}
}
/*平方运算的比较*/
void Test_equare1()
{
int a;
int i;
for(i=0; i<MAX; i++)
{
a=55;
a=pow(a, 2); /*用库函数*/
/* a*=a; */ /*用常用算法*/
/* a<<=2; */ /*用移位的方法*/
}
}
/*只要是乘以或除以一个整数,均可以用移位的方法得到结果*/
/**比如a=a*9 *****/
void Test_equare2()
{
int a;
int i;
for(i=0; i<MAX; i++)
{
a=55;
/* a=pow(a, 9); */ /*用库函数*/
/* a*=9; */
a = (a <<3)+a; /*用移位的方法*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -