Syn*_*ose 3 c c++ performance if-statement shorthand
如果我有一个包含任意长度整数的大型数据文件需要按其第二个字段排序:
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
Run Code Online (Sandbox Code Playgroud)
并且我呼吁qsort成为我的选择武器,在我的排序功能中,将使用速记IF为数据整理所需的总体时间提供显着的性能提升?或简称IF仅用作组织代码的便利工具?
num2 = atoi(Str);
num1 = atoi(Str2);
LoggNum = (num2 > num1) ? num2 : num1; //faster?
Run Code Online (Sandbox Code Playgroud)
num2 = atoi(Str);
num1 = atoi(Str2);
if(num2 > num1) //or the same?
LoggNum = num2;
else
LoggNum = num1;
Run Code Online (Sandbox Code Playgroud)
Ele*_*tal 10
任何现代编译器都会在这两种情况下构建相同的代码,区别仅在于样式和方便.