Csharp/C Sharp by API/System.Diagnostics/Stopwatch — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:13, 26 мая 2010

Stopwatch.ElapsedMilliseconds

  
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.rupilerServices;
using System.Threading;
public class MainClass
{
    public static void Main()
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine("Parse pattern took {0}ms", sw.ElapsedMilliseconds);
        sw.Reset();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine("TryParse pattern took {0}ms", sw.ElapsedMilliseconds);
    }
}


Stopwatch.ElapsedTicks

  
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.rupilerServices;
using System.Threading;
public class MainClass
{
    public static void Main()
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine(sw.ElapsedTicks);
        sw.Reset();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine("TryParse pattern took {0}ms", sw.ElapsedMilliseconds);
    }
}


Stopwatch.Reset()

  
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.rupilerServices;
using System.Threading;
public class MainClass
{
    public static void Main()
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine("Parse pattern took {0}ms", sw.ElapsedMilliseconds);
        sw.Reset();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine("TryParse pattern took {0}ms", sw.ElapsedMilliseconds);
    }
}


Stopwatch.Start()

  
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.rupilerServices;
using System.Threading;
public class MainClass
{
    public static void Main()
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine("Parse pattern took {0}ms", sw.ElapsedMilliseconds);
        sw.Reset();
        sw.Start();
        for (int i = 0; i < 1000; i++)
        {
        }
        sw.Stop();
        Console.WriteLine("TryParse pattern took {0}ms", sw.ElapsedMilliseconds);
    }
}