final class · System.Diagnostics
Stopwatch
public final class Stopwatch
Measures elapsed time, from the runtime's monotonic clock in nanoseconds.
- Tipo
- final class
- Espacio de nombres
- System.Diagnostics
- Ensamblado
- System.Core
- Acceso
- public, final
- Archivo fuente
Runtime.ant
Herencia
- Clases base
-
AnyStopwatch
Propiedades
Ticks of GetTimestamp and ElapsedTicks per second (they are nanoseconds).
Métodos
The clock now, in ticks of Frequency.
The time from a timestamp to now, and between two.
Start()
#
Stop()
#
Reset()
#
Restart()
#
Miembros privados e internos (5)
Miembros heredados (5)
GetTypemétodo de AnyUndescribedmétodo de AnyToStringmétodo de AnyHashmétodo de Anydestroymétodo de Any
Código fuente
Stopwatch en Antril, descompilado a partir de su Larva HIR.
// System.Diagnostics.Stopwatch — System.Core (decompiled from Larva HIR)
import System;
into namespace System.Diagnostics
{
/// Measures elapsed time, from the runtime's monotonic clock in nanoseconds.
public final class Stopwatch
{
i64 started;
i64 elapsed;
bool running;
static extern("time.precise") Now() : i64;
/// Nanoseconds so far.
Nanoseconds() : i64 => running ? elapsed + Now() - started : elapsed;
public:
/// The clock now, in ticks of Frequency.
static GetTimestamp() : i64 => Now();
/// The time from a timestamp to now, and between two.
static GetElapsedTime(i64 start) : TimeSpan => new TimeSpan((Now() - start) / 100);
static GetElapsedTime(i64 start, i64 end) : TimeSpan => new TimeSpan((end - start) / 100);
static StartNew() : Stopwatch
{
Stopwatch watch = new Stopwatch();
watch.Start();
return watch;
}
Start()
{
if (!running)
{
started = Now();
running = true;
}
}
Stop()
{
if (running)
{
elapsed += Now() - started;
running = false;
}
}
Reset()
{
elapsed = 0;
running = false;
}
Restart()
{
elapsed = 0;
started = Now();
running = true;
}
/// Ticks of GetTimestamp and ElapsedTicks per second (they are nanoseconds).
static i64 Frequency
{
get => 1000000000;
}
static bool IsHighResolution
{
get => true;
}
bool IsRunning
{
get => running;
}
TimeSpan Elapsed
{
get => new TimeSpan(Nanoseconds() / 100);
}
i64 ElapsedMilliseconds
{
get => Nanoseconds() / 1000000;
}
i64 ElapsedTicks
{
get => Nanoseconds();
}
}
}