Baza znanjaIzpitno središče
SLSlovenščina
Izberi jezik13

CKTIS / C#

System.Diagnostics.Stopwatch: praktična referenca

System.Diagnostics.Stopwatch: praktična referenca: Stopwatch meri pretekle intervale s frekvenco Stopwatch.Frequency; če je Stopwatch.IsHighResolution true, uporabi strojni ali sistemski števec visoke ločljivosti, sicer sistemski časovnik.

Različica: .NET API; verified on .NET 10.0.14

Sintaksa

System.Diagnostics.Stopwatch /* select a documented member or constructor */

Stopwatch meri pretekle intervale s frekvenco Stopwatch.Frequency; če je Stopwatch.IsHighResolution true, uporabi strojni ali sistemski števec visoke ločljivosti, sicer sistemski časovnik.

Uporabite ga za diagnostične časovne omejitve in meritve trajanja, ne za časovne žige stenske ure.

Mikrobenchmark zahteva ogrevanje in ponovljene poskuse, ker ena meritev vsebuje šum okolja.

Elapsed ni negativen; Start po Stop nadaljuje seštevanje, Restart pa počisti in znova zažene.

Celoten program dejansko uporabi System.Diagnostics.Stopwatch; natančno pričakovani stdout je True.

Primeri

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);

Rezultat

True

Celoten program dejansko uporabi `System.Diagnostics.Stopwatch`; natančno pričakovani stdout je `True`.

Viri