CKTIS / C#
System.Diagnostics.Stopwatch: referencia práctica
System.Diagnostics.Stopwatch: referencia práctica: Stopwatch mide intervalos transcurridos con Stopwatch.Frequency; si Stopwatch.IsHighResolution es true usa un contador de hardware o del sistema operativo de alta resolución y, en caso contrario, el temporizador del sistema.
Versión: .NET API; verified on .NET 10.0.14
Sintaxis
System.Diagnostics.Stopwatch /* select a documented member or constructor */Stopwatch mide intervalos transcurridos con Stopwatch.Frequency; si Stopwatch.IsHighResolution es true usa un contador de hardware o del sistema operativo de alta resolución y, en caso contrario, el temporizador del sistema.
Úsalo para tiempos de espera diagnósticos y medición de duraciones, no para marcas del reloj de pared.
Un microbenchmark requiere calentamiento y ensayos repetidos porque una medición incluye ruido ambiental.
Elapsed no es negativo; Start después de Stop continúa acumulando y Restart borra y vuelve a iniciar.
El programa completo usa realmente System.Diagnostics.Stopwatch; su stdout esperado exacto es True.
Ejemplos
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var watch = Stopwatch.StartNew();
watch.Stop();
Console.WriteLine(watch.Elapsed >= TimeSpan.Zero);
Resultado
True
El programa completo usa realmente `System.Diagnostics.Stopwatch`; su stdout esperado exacto es `True`.