首页 > 编程语言 >C#中检测代码执行时间

C#中检测代码执行时间

时间:2023-01-29 19:35:00浏览次数:31  
标签:00 TimeSpan C# 检测 System ts Stopwatch 代码执行 stopWatch

 使用System.Diagnostics.Stopwatch,

using System;
using System.Diagnostics;
using System.Threading;
class Program
{
    static void Main(string[] args)
    {
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        Thread.Sleep(10000);
        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value.
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine("RunTime " + elapsedTime);
    }
}

https://learn.microsoft.com/zh-cn/dotnet/api/system.diagnostics.stopwatch?view=net-7.0

标签:00,TimeSpan,C#,检测,System,ts,Stopwatch,代码执行,stopWatch
From: https://www.cnblogs.com/kuluodisi/p/17073664.html

相关文章

  • .net core 使用redis
    参照:.NET6使用Redis-Lulus-博客园(cnblogs.com)九、.netcore(.NET6)添加通用的Redis功能-WeskyNet-博客园(cnblogs.com)......
  • CRT&EXCRT(中国剩余定理和扩展中国剩余定理)
    稍微难一点,其实也挺简单。CRT:用途:给定一个同余方程组,保证所有\(m\)两两互质:\[\begin{cases}x\equiva_1\pmod{m_1}\\x\equiva_2\pmod{m_2}\\...\\x\equiv......
  • leetcode 15. 三数之和
    想到了先排序然后再用双指针,可是没有想过往O(n^2)的时间复杂度上怼。哈哈哈。正确解法如下:classSolution{publicList<List<Integer>>threeSum(int[]nums){......
  • TypeScript踩坑记录
    设置experimentalDecorators无效errorTS1219:Experimentalsupportfordecoratorsisafeaturethatissubjecttochangeinafuturerelease.Setthe'experi......
  • 1013 Battle Over Cities
    1013BattleOverCities题目描述题意理解题意很简单,给出一张图,问如果去掉其中一个节点以及与这条节点相连的边,需要再添加几条边才能使图重新连通。解题的关键在于找......
  • POJ--3723 Conscription(最小生成树)
    记录18:302023-1-29http://poj.org/problem?id=3723reference:《挑战程序设计竞赛(第2版)》2.5.6p109DescriptionWindyhasacountry,andhewantstobuildana......
  • 「解题报告」ARC136F Flip Cells
    感觉AtCoder上高于铜的难度就完全是随机了,这题完全是金吧,怎么可能只有铜啊,我快写自闭了。以下记\(n=hw\)。我们设三个DP数组:\(f_i\)为从初始状态经过\(i\)步之......
  • OutputDebugString在X64出现异常 0xC0000005
    xxxxx.exe中的0x78ebb746处最可能的异常:0xC0000005:读取位置0xffffffffffffffff时发生访问冲突对应位置指令0000000078EBB7460FAE8100010000fxsave......
  • monaco编辑器的基础api使用
    目录添加js/ts扩展库添加js扩展库添加ts扩展库添加js/ts扩展库添加js扩展库1.使用addExtraLibfilePath同名会覆盖monaco.languages.typescript.javascriptDefaults.ad......
  • Surface Pro (1796),安装Win11之后出现的问题。
    2020年年中我为了体验微软新的操作系统,加入了Review计划,即:Windows预览体验计划。然后升级到了Win11。由于苏菲一直是作为辅助设备用,所以平时就是开节电模式,中途也升级了几......