测试一个方法的运行时间

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace UserPai
{
class Program
{
static decimal pai;
static decimal loop;
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 1; i < 100000001; i++)
{
loop = (decimal)1 / (2 * i-1);

if (i % 2 == 0)
{
loop = -loop;
}
pai += loop;
}
sw.Stop();
Console.WriteLine( 4*pai);
Console.WriteLine(sw.ElapsedMilliseconds);
Console.ReadLine();
}
}
}

Stopwatch

你可能感兴趣的:(测试)