当前位置: 首页>>代码示例>>C#>>正文


C# Stopwatch.Time方法代码示例

本文整理汇总了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);
 }
开发者ID:BasDeBlok,项目名称:CS247,代码行数:7,代码来源:PerformanceTests.cs

示例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);
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:24,代码来源:MultiplexingSampleProviderTests.cs

示例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);
        }
开发者ID:ArsenShnurkov,项目名称:BitSharp,代码行数:57,代码来源:PruningWorker.cs

示例4: ShortTest

 public void ShortTest()
 {
     Stopwatch timer = new Stopwatch();
     long ms = timer.Time(() => ReadFromTestProvider(16 * 1024, 4096));
     Console.WriteLine("{0} ms", ms);
 }
开发者ID:BasDeBlok,项目名称:CS247,代码行数:6,代码来源:PerformanceTests.cs


注:本文中的Stopwatch.Time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。