#include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a(100), b(50), n(100000), temp;
clock_t start = clock();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (a > b)
temp = a;
else
temp = b;
}
}
clock_t end = clock();
cout << "IF Time = " << end - start << endl;
start = clock();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
temp = a > b ? a : b;
}
}
end = clock();
cout << "?: Time = " << end - start << endl;
return 0;
}
三目运算符?:与If效率对比
最新推荐文章于 2024-07-11 10:28:35 发布