将速记如果与默认的IF提供一个效率提升? [英] Will a shorthand IF provide an efficiency boost compared to the default IF?
本文介绍了将速记如果与默认的IF提供一个效率提升?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个包含任意长度需要通过它进行排序的整数一个大的数据文件的第二个字段:
1 3 4 5
1 4 5 7
-1 34 56 7
124 58394 1384 -1938
1948年3848089 -14850 0
1048 01840 1039 888
//认为这是一个大的文件时,数据持续了相当长一段时间
和我呼吁的qsort是我的首选武器,我的排序函数内部,将使用速记IF提供显著的性能提升所花费的数据总体时间进行排序?或者是速记如果仅仅作为一个便利工具,组织code?
NUM2 =的atoi(STR);
NUM1 =的atoi(STR2);
LoggNum =(NUM2> NUM1)? NUM2:NUM1; //更快?
NUM2 =的atoi(STR);
NUM1 =的atoi(STR2);
如果(NUM2> NUM1)//还是一样的吗?
LoggNum = NUM2;
其他
LoggNum = NUM1;
解决方案
任何现代编译器将建立在这两种情况下相同的code,所不同的是风格之一,仅为方便。
If i have a large data file containing integers of an arbitrary length needing to be sorted by it's second field:
1 3 4 5
1 4 5 7
-1 34 56 7
124 58394 1384 -1938
1948 3848089 -14850 0
1048 01840 1039 888
//consider this is a LARGE file, the data goes on for quite some time
and i call upon qsort to be my weapon of choice, inside my sort function, will using the shorthand IF provide a significant performance boost to overall time it takes the data to be sorted? Or is the shorthand IF only used as a convenience tool for organizing code?
num2 = atoi(Str);
num1 = atoi(Str2);
LoggNum = (num2 > num1) ? num2 : num1; //faster?
num2 = atoi(Str);
num1 = atoi(Str2);
if(num2 > num1) //or the same?
LoggNum = num2;
else
LoggNum = num1;
解决方案
Any modern compiler will build identical code in these two cases, the difference is one of style and convenience only.
这篇关于将速记如果与默认的IF提供一个效率提升?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文