CKTIS / C#
System.Diagnostics.Stopwatch: praktická referencia
System.Diagnostics.Stopwatch: praktická referencia: Stopwatch meria uplynulé intervaly s frekvenciou Stopwatch.Frequency; ak je Stopwatch.IsHighResolution true, používa hardvérový alebo systémový čítač s vysokým rozlíšením, inak systémový časovač.
Verzia: .NET API; verified on .NET 10.0.14
Syntax
System.Diagnostics.Stopwatch /* select a documented member or constructor */Stopwatch meria uplynulé intervaly s frekvenciou Stopwatch.Frequency; ak je Stopwatch.IsHighResolution true, používa hardvérový alebo systémový čítač s vysokým rozlíšením, inak systémový časovač.
Použite ho na diagnostické timeouty a meranie trvania, nie na časové pečiatky nástenných hodín.
Mikrobenchmark vyžaduje zahriatie a opakované pokusy, pretože jedno meranie obsahuje šum prostredia.
Elapsed je nezáporné; Start po Stop pokračuje v načítaní, kým Restart vynuluje a znova spustí.
Úplný program skutočne používa System.Diagnostics.Stopwatch; presne očakávaný stdout je True.
Príklady
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);
Výsledok
True
Úplný program skutočne používa `System.Diagnostics.Stopwatch`; presne očakávaný stdout je `True`.