C# 程式效率(時間差) 計算和顯示程式碼檔案&行號 通用函示庫
C# 程式效率(時間差) 計算和顯示程式碼檔案&行號 通用函示庫
資料來源: https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/221419/
http://jashliao.eu/wordpress/2015/10/06/c-%e8%a8%88%e7%ae%97%e6%99%82%e9%96%93%e5%b7%ae/
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;//Stopwatch
namespace CS_VPOS
{
public class ConsumeTime
{
private static Stopwatch m_stopWatch = new Stopwatch();
private static String m_StrTitle = "";
private static String m_StrStartFileLine = "";
private static String m_StrEndFileLine = "";
public static void Start(String StrInfor)
{
StackFrame CallStack = new StackFrame(1, true);
m_StrStartFileLine = String.Format("File : {0} , Line : {1}", CallStack.GetFileName(), CallStack.GetFileLineNumber());
m_StrTitle = StrInfor;
m_stopWatch.Start();
}
public static void Stop()
{
StackFrame CallStack = new StackFrame(1, true);
m_stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = m_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);
m_StrEndFileLine = String.Format("File : {0} , Line : {1}", CallStack.GetFileName(), CallStack.GetFileLineNumber());
MessageBox.Show(m_StrStartFileLine + " ~ " + m_StrEndFileLine + " consume time: " + elapsedTime, m_StrTitle);
}
}
}
功能:計算相關演算法的所需執行時間,[UI反應時間一般規定3秒,SQL 查詢時間一般只占全部1/6=0.5秒]
One thought on “C# 程式效率(時間差) 計算和顯示程式碼檔案&行號 通用函示庫”
[程式/軟體 UI 介面 容忍 等待 反應 時間一般規定3秒,SQL 查詢時間一般只占全部1/6 = 0.5秒 ]