我有一个填充随机板的过程,希望以最有效的方式,我有一个我正在运行的循环,我想从循环的开始到它完成像秒表这样的时间然后我可以将一个路径寻找算法的结果与另一个路径寻找算法进行比较,我之前没有使用这样的定时器,也不确定我是否会采用错误的方式.
这,我希望更多地展示我正在尝试做的事情
System.Timers.Timer gameTime = new System.Timers.Timer();
gameTime.Interval = (1000);
gameTime.Enabled = true;
gameTime.Start();
m_turn = 1;
do
{
//Proccess here
m_turn++
while(m_turn <= 1000)
gameTime.Stop();
string printTime = gameTime. //The amount of times the interval has passed?
Run Code Online (Sandbox Code Playgroud)
由于你想测量时间间隔我会使用StopWatch而不是Timer:
var sw = System.Diagnostics.StopWatch.StartNew();
PerformSecretAlgorithm();
sw.Stop();
long elapsed = sw.ElapsedMilliseconds();
Run Code Online (Sandbox Code Playgroud)