本文整理汇总了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)));
}
示例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("=====================================================================");
}