Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Propiedad Stopwatch.ElapsedTicks

 

Publicado: octubre de 2016

Obtiene el tiempo total transcurrido medido por la instancia actual, en tics de temporizador.

Espacio de nombres:   System.Diagnostics
Ensamblado:  System (en System.dll)

public long ElapsedTicks { get; }

Valor de propiedad

Type: System.Int64

Un entero largo de solo lectura que representa el número total de tics de temporizador medido por la instancia actual.

This property represents the number of elapsed ticks in the underlying timer mechanism. A tick is the smallest unit of time that the T:System.Diagnostics.Stopwatch timer can measure. Use the F:System.Diagnostics.Stopwatch.Frequency field to convert the P:System.Diagnostics.Stopwatch.ElapsedTicks value into a number of seconds.

You can query the properties P:System.Diagnostics.Stopwatch.Elapsed, P:System.Diagnostics.Stopwatch.ElapsedMilliseconds, and P:System.Diagnostics.Stopwatch.ElapsedTicks while the T:System.Diagnostics.Stopwatch instance is running or stopped. The elapsed time properties steadily increase while the T:System.Diagnostics.Stopwatch is running; they remain constant when the instance is stopped.

By default, the elapsed time value of a T:System.Diagnostics.Stopwatch instance equals the total of all measured time intervals. Each call to M:System.Diagnostics.Stopwatch.Start begins counting at the cumulative elapsed time; each call to M:System.Diagnostics.Stopwatch.Stop ends the current interval measurement and freezes the cumulative elapsed time value. Use the M:System.Diagnostics.Stopwatch.Reset method to clear the cumulative elapsed time in an existing T:System.Diagnostics.Stopwatch instance.

System_CAPS_noteNota

Stopwatch ticks are different from DateTime.Ticks. Each tick in the DateTime.Ticks value represents one 100-nanosecond interval. Each tick in the ElapsedTicks value represents the time interval equal to 1 second divided by the Frequency.

The following example uses the T:System.Diagnostics.Stopwatch class to measure the performance of four different implementations for parsing an integer from a string. This code example is part of a larger example provided for the T:System.Diagnostics.Stopwatch class.

long ticksThisTime = 0;
int inputNum;
Stopwatch timePerParse;

switch (operation)
{
    case 0:
        // Parse a valid integer using
        // a try-catch statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        try 
        {
            inputNum = Int32.Parse("0");
        }
        catch (FormatException)
        {
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.

        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;
    case 1:
        // Parse a valid integer using
        // the TryParse statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        if (!Int32.TryParse("0", out inputNum))
        { 
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.
        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;
    case 2:
        // Parse an invalid value using
        // a try-catch statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        try 
        {
            inputNum = Int32.Parse("a");
        }
        catch (FormatException)
        {
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.
        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;
    case 3:
        // Parse an invalid value using
        // the TryParse statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        if (!Int32.TryParse("a", out inputNum))
        { 
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.
        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;

    default:
        break;
}

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 2.0
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1
Volver al principio
Mostrar: