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


C# TimeSpan.OrderBy方法代码示例

本文整理汇总了C#中System.TimeSpan.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.OrderBy方法的具体用法?C# TimeSpan.OrderBy怎么用?C# TimeSpan.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.OrderBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        /// <summary>
        /// Measures the time required to run this benchmark.
        /// </summary>
        /// <returns>The time that it took to run this benchmark.</returns>
        public TimeSpan Run()
        {
            WarmUp();

            Stopwatch sw = new Stopwatch();

            // Make sure that each interation takes over 100ms
            // We do this to make sure the Stopwatch is keeping time accurately
            sw.Start();
            MethodToBenchmark();
            sw.Stop();

            // If it isn't, do enough calls so that it is above 100ms
            int callsPerInteration = sw.Elapsed.TotalMilliseconds < 100 ? (int)Math.Ceiling(100 / sw.Elapsed.TotalMilliseconds) + 1 : 1;

            sw.Reset();

            TimeSpan[] times = new TimeSpan[_timesToRun];
            for (int i = 0; i < _timesToRun; i++)
            {
                sw.Start();

                for (int j = 0; j < callsPerInteration; j++)
                {
                    MethodToBenchmark();
                }

                sw.Stop();

                times[i] = new TimeSpan((int)Math.Round(sw.Elapsed.Ticks / (double)callsPerInteration));
                sw.Reset();
            }

            // Throw out the top and bottom 25% as outliers
            return new TimeSpan((int)Math.Round(times.OrderBy(x => x.Ticks).Skip(_timesToRun / 4).Take(_timesToRun / 2).Average(x => x.Ticks)));
        }
开发者ID:mgbowen,项目名称:graphing-calc-csharp,代码行数:40,代码来源:BenchmarkBase.cs

示例2: Benchmark2

        public void Benchmark2()
        {
            var sw = new Stopwatch();
            var times = new TimeSpan[10];

            for (var i = 0; i < 10; i++)
            {
                sw.Start();

                var allFriends = this.db.Views.QueryAsync<Person>(new QueryViewRequest("person", "all_friends")).Result;

                var randomPerson = allFriends.Rows.RandomEntry(this.rng).Value;

                var friendsFromRandom = this.RelationsFrom(randomPerson, "Friend").ToList();

                var friendsFromFriendsFromRandom = friendsFromRandom.SelectMany(x => this.RelationsFrom(x, "Friend")).ToList();

                Console.WriteLine("Count results : " + friendsFromFriendsFromRandom.Count);
                times[i] = sw.Elapsed;
                sw.Stop();
                sw.Reset();
            }
            Console.WriteLine("=====================================================================");
            Console.WriteLine("Min time : " + times.Min());
            Console.WriteLine("Max time : " + times.Max());
            Console.WriteLine("Average time : " + TimeSpan.FromTicks((long)times.Average(x => x.Ticks)));
            Console.WriteLine("Median time : " + times.OrderBy(x => x).ElementAt(times.Length / 2));
            Console.WriteLine("=====================================================================");
        }
开发者ID:Uwy,项目名称:TpNoSQL-CouchDB,代码行数:29,代码来源:CouchDBBenchmark.cs


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