本文整理汇总了C#中Stopwatch.GetElapsedNanoSeconds方法的典型用法代码示例。如果您正苦于以下问题:C# Stopwatch.GetElapsedNanoSeconds方法的具体用法?C# Stopwatch.GetElapsedNanoSeconds怎么用?C# Stopwatch.GetElapsedNanoSeconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.GetElapsedNanoSeconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitStopwatchTimeCostNs
private void InitStopwatchTimeCostNs()
{
long iterations = 10000000;
var stopwatch = new Stopwatch();
stopwatch.Start();
//the stopwatch does the elapsed time so we don't need to maintain a start/finish
//set to do the math ourselves. We do however need a variable to assign to in order
//make sure the runtime invokes stopwatch.ElapsedTicks in our loop
long dummy = stopwatch.GetElapsedNanoSeconds();
for (int i = 0; i < iterations; i++)
{
dummy = stopwatch.GetElapsedNanoSeconds();
}
dummy = stopwatch.GetElapsedNanoSeconds();
stopwatch.Stop();
_stopwatchTimeCostNs = stopwatch.GetElapsedNanoSeconds() / iterations;
}