测试一个方法的运行时间

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

posted on 2013-06-08 15:41  水行者  阅读(217)  评论(0编辑  收藏  举报

导航