CKTIS / C#
System.Diagnostics.Stopwatch: riferimento pratico
System.Diagnostics.Stopwatch: riferimento pratico: Stopwatch misura gli intervalli trascorsi alla frequenza Stopwatch.Frequency; quando Stopwatch.IsHighResolution è true usa un contatore hardware o del sistema operativo ad alta risoluzione, altrimenti il timer di sistema.
Versione: .NET API; verified on .NET 10.0.14
Sintassi
System.Diagnostics.Stopwatch /* select a documented member or constructor */Stopwatch misura gli intervalli trascorsi alla frequenza Stopwatch.Frequency; quando Stopwatch.IsHighResolution è true usa un contatore hardware o del sistema operativo ad alta risoluzione, altrimenti il timer di sistema.
Usalo per timeout diagnostici e misure di durata, non per timestamp dell’orologio civile.
Un microbenchmark richiede warm-up e prove ripetute perché una singola misura include rumore ambientale.
Elapsed non è negativo; Start dopo Stop continua ad accumulare, mentre Restart azzera e riparte.
Il programma completo usa realmente System.Diagnostics.Stopwatch; lo stdout esatto atteso è True.
Esempi
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);
Risultato
True
Il programma completo usa realmente `System.Diagnostics.Stopwatch`; lo stdout esatto atteso è `True`.