我是靠谱客的博主 诚心店员,最近开发中收集的这篇文章主要介绍c语言函数传递参数太多,c语言函数参数太多对性能是否有影响?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#includetypedef struct fun_p{

char c;

int a;

int b;

int d;

long f;

}_funp;

int func(int aa, int bb, int cc, int dd, char c, int a, int b, int d, double f)

{

int ret = 0;

if(c > 10)

ret = c*c + a + b + d + f * 2;

else

ret = a + b + d + f * 2;

return ret + aa + bb + cc + dd;

}

int funcs(int aa, int bb, int cc, int dd, _funp * inp)

{

int ret = 0;

char c = inp->c;

int a = inp->a;

int b = inp->b;

int d = inp->d;

double f = inp->f;

if(c > 10)

ret = c*c + a + b + d + f * 2;

else

ret = a + b + d + f * 2;

return ret + aa + bb + cc + dd;

}

int funcs2(int aa, int bb, int cc, int dd, _funp * inp)

{

int ret = 0;

char c = inp->c;

if(c > 10)

ret = c*c + inp->a + inp->b + inp->d + inp->f * 2;

else

ret = inp->a + inp->b + inp->d + inp->f * 2;

return ret + aa + bb + cc + dd;

}

int main(void)

{

struct timespec time_start = {0, 0}, time_end = {0, 0};

int aa = 9;

int bb = 12;

int cc = 39;

int dd = 90;

char c = 20;

int a = 98;

int b = 199;

int d = 23;

double f = 34.2;

struct fun_p funp;

int i, j;

int run_num = 1000;

long long total = 0;

funp.c = c;

funp.a = a;

funp.b = b;

funp.d = d;

funp.f = f;

clock_gettime(CLOCK_REALTIME, &time_start);

for (i = 0; i < run_num; i++)

for (j = 0; j < run_num; j++){

c = c + 1;

total += func(aa, bb, cc, dd, c, a, b, d, f);

}

clock_gettime(CLOCK_REALTIME, &time_end);

printf("func duration:%llus %lluns. total = %lld

", time_end.tv_sec-time_start.tv_sec, time_end.tv_nsec-time_start.tv_nsec, total);

total = 0;

c = 20;

clock_gettime(CLOCK_REALTIME, &time_start);

for (i = 0; i < run_num; i++)

for (j = 0; j < run_num; j++){

funp.c = funp.c + 1;

total += funcs(aa, bb, cc, dd, &funp);

}

clock_gettime(CLOCK_REALTIME, &time_end);

printf("funcs duration:%llus %lluns. total = %lld

", time_end.tv_sec-time_start.tv_sec, time_end.tv_nsec-time_start.tv_nsec, total);

total = 0;

funp.c = 20;

clock_gettime(CLOCK_REALTIME, &time_start);

for (i = 0; i < run_num; i++)

for (j = 0; j < run_num; j++){

funp.c = funp.c + 1;

total += funcs2(aa, bb, cc, dd, &funp);

}

clock_gettime(CLOCK_REALTIME, &time_end);

printf("funcs2 duration:%llus %lluns. total = %lld

", time_end.tv_sec-time_start.tv_sec, time_end.tv_nsec-time_start.tv_nsec, total);

return 1;

}

最后

以上就是诚心店员为你收集整理的c语言函数传递参数太多,c语言函数参数太多对性能是否有影响?的全部内容,希望文章能够帮你解决c语言函数传递参数太多,c语言函数参数太多对性能是否有影响?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部