用&判断是否是一个偶数或许是不错的选择

&有很多妙用,在此只简单的演示下用了判断是否是偶数

void Main()
{
Stopwatch stopwatch = new Stopwatch();
 //运算次数
int cnt =10000000;
stopwatch.Start();  
for(int i =0 ;i <cnt;i++)
{
   if(i%2==0)
   continue;
}	
stopwatch.Stop(); 
Console.WriteLine($"i%2==0  运算{cnt}次  ;耗时{ stopwatch.ElapsedMilliseconds}毫秒" );//这里面使用毫秒来输出
Console.WriteLine("===================================================");

stopwatch.Reset();

stopwatch.Start();  
for(int i =0 ;i <cnt;i++)
{
   if((i&1)==0)
    continue;
}

stopwatch.Stop(); 
Console.WriteLine($"(i&1)==0 运算{cnt}次 ;耗时{stopwatch.ElapsedMilliseconds}毫秒");//这里面使用毫秒来输出
Console.WriteLine("===================================================");



}

// Define other methods and classes here

result:

posted @ 2017-05-04 11:13  求道者  阅读(247)  评论(0)    收藏  举报