本文整理汇总了C#中Stopwatch.Time方法的典型用法代码示例。如果您正苦于以下问题:C# Stopwatch.Time方法的具体用法?C# Stopwatch.Time怎么用?C# Stopwatch.Time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.Time方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TimingTest
public void TimingTest()
{
Stopwatch timer = new Stopwatch();
int iterations = 10;
long ms = timer.Time(() => ReadFromTestProvider(1024 * 1024, 4096), iterations);
Console.WriteLine("{0} ms", ms);
}
示例2: PerformanceTest
public void PerformanceTest()
{
var input1 = new TestSampleProvider(32000, 1);
var input2 = new TestSampleProvider(32000, 1);
var input3 = new TestSampleProvider(32000, 1);
var input4 = new TestSampleProvider(32000, 1);
var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1, input2, input3, input4 }, 4);
mp.ConnectInputToOutput(0, 3);
mp.ConnectInputToOutput(1, 2);
mp.ConnectInputToOutput(2, 1);
mp.ConnectInputToOutput(3, 0);
float[] buffer = new float[input1.WaveFormat.AverageBytesPerSecond / 4];
Stopwatch s = new Stopwatch();
var duration = s.Time(() =>
{
// read one hour worth of audio
for (int n = 0; n < 60 * 60; n++)
{
mp.Read(buffer, 0, buffer.Length);
}
});
Console.WriteLine("Performance test took {0}ms", duration);
}
示例3: PruneBlock
private async Task PruneBlock(PruningMode mode, Chain chain, ChainedHeader pruneBlock)
{
//TODO the replay information about blocks that have been rolled back also needs to be pruned (UnmintedTx)
var txCount = 0;
var totalStopwatch = Stopwatch.StartNew();
var pruneBlockTxesStopwatch = new Stopwatch();
var pruneTxIndexStopwatch = new Stopwatch();
var pruneSpentTxesStopwatch = new Stopwatch();
// retrieve the spent txes for this block
BlockSpentTxes spentTxes;
using (var handle = this.storageManager.OpenChainStateCursor())
{
var chainStateCursor = handle.Item;
chainStateCursor.BeginTransaction(readOnly: true);
chainStateCursor.TryGetBlockSpentTxes(pruneBlock.Height, out spentTxes);
}
if (spentTxes != null)
{
txCount = spentTxes.Count;
pruneBlockTxesStopwatch.Start();
pruneTxIndexStopwatch.Start();
await Task.WhenAll(
// prune block txes (either merkle prune or delete)
PruneBlockTxesAsync(mode, chain, pruneBlock, spentTxes)
.ContinueWith(task => { pruneBlockTxesStopwatch.Stop(); task.Wait(); }),
// prune tx index
PruneTxIndexAsync(mode, chain, pruneBlock, spentTxes)
.ContinueWith(task => { pruneTxIndexStopwatch.Stop(); task.Wait(); })
);
// remove block spent txes information
//TODO should have a buffer on removing this, block txes pruning may need it again if flush doesn't happen
pruneSpentTxesStopwatch.Time(() =>
PruneBlockSpentTxes(mode, chain, pruneBlock));
}
else //if (pruneBlock.Height > 0)
{
//TODO can't throw an exception unless the pruned chain is persisted
//logger.Info("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: {0:N0}".Format2(pruneBlock.Height));
//throw new InvalidOperationException();
txCount = 0;
}
// track stats
txCountMeasure.Tick(txCount);
txRateMeasure.Tick((float)(txCount / totalStopwatch.Elapsed.TotalSeconds));
pruneBlockTxesDurationMeasure.Tick(pruneBlockTxesStopwatch.Elapsed);
pruneTxIndexDurationMeasure.Tick(pruneTxIndexStopwatch.Elapsed);
pruneSpentTxesDurationMeasure.Tick(pruneSpentTxesStopwatch.Elapsed);
totalDurationMeasure.Tick(totalStopwatch.Elapsed);
}
示例4: ShortTest
public void ShortTest()
{
Stopwatch timer = new Stopwatch();
long ms = timer.Time(() => ReadFromTestProvider(16 * 1024, 4096));
Console.WriteLine("{0} ms", ms);
}