62,268
社区成员
发帖
与我相关
我的任务
分享

static void Main(string[] args)
{
int a;
int c;
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000000000; i++)
{
a = 1234;
c=a % 10;
if(c==0)
c=10-c;
a = a + c;
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
int b;
sw.Reset();
sw.Start();
for (int i = 0; i < 1000000000; i++)
{
a = 1234;
b = a / 10 * 10;
if (b < a)
{
b += 10;
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read();
}
static void Main(string[] args)
{
int a;
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000000000; i++)
{
a = 1234;
a = a % 10;
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
int b;
sw.Reset();
sw.Start();
for (int i = 0; i < 1000000000; i++)
{
a = 1234;
a = a / 10;
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read();
} static void Main(string[] args)
{
int a;
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 100000000; i++)
{
a = 1234;
a = a + 10 - a % 10;
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
sw.Reset();
sw.Start();
StringBuilder sb = new StringBuilder();
int b;
for (int i = 0; i < 100000000; i++)
{
a = 1234;
b = a / 10 * 10;
if (b < a)
{
b += 10;
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read();
}
