本文整理汇总了C#中NUnit.Framework.List.Average方法的典型用法代码示例。如果您正苦于以下问题:C# List.Average方法的具体用法?C# List.Average怎么用?C# List.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.Average方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckReadPerformance
public void CheckReadPerformance(int numberOfEvents)
{
var stopwatch = Stopwatch.StartNew();
WriteEvents(numberOfEvents);
var seconds = stopwatch.Elapsed.TotalSeconds;
Console.WriteLine("Writing {0} events took {1:0.0} s - that's {2:0.0} events/s", numberOfEvents, seconds, numberOfEvents / seconds);
var measuredSeconds = new List<Tuple<double, int>>();
100.Times(() =>
{
var readStopwatch = Stopwatch.StartNew();
var randomAggregateRootId = GetRandomAggregateRootId();
var events = _eventStore.Load(randomAggregateRootId).ToList();
measuredSeconds.Add(Tuple.Create(readStopwatch.Elapsed.TotalSeconds, events.Count));
});
Console.WriteLine("Reading entire root event stream took {0:0.0} for {1:0.0} events - that's {2:0.0} events/s (AVG)",
measuredSeconds.Average(a => a.Item1), measuredSeconds.Average(a => a.Item2), measuredSeconds.Average(a => a.Item2)/measuredSeconds.Average(a => a.Item1));
var streamStopwatch = Stopwatch.StartNew();
var counter = 0;
foreach (var e in _eventStore.Stream())
{
counter++;
}
var totalSeconds = streamStopwatch.Elapsed.TotalSeconds;
Console.WriteLine("Streaming all events took {0:0.0} s for {1} events - that's {2:0.0} events/s",
totalSeconds, counter, counter/ totalSeconds);
}
示例2: Can_get_few_records_test
public void Can_get_few_records_test()
{
var efDriver = new EFDriver();
var times = new List<double>();
for (int i = 0; i < 100; ++i)
{
var sw = Stopwatch.StartNew();
var rows = efDriver.GetAFewRecords();
Assert.That(rows, Is.Not.Null);
Assert.That(rows.Count(), Is.GreaterThan(0));
sw.Stop();
times.Add(sw.ElapsedMilliseconds);
Console.WriteLine("took {0} ms to get {1} records",
sw.ElapsedMilliseconds,
rows.Count());
}
Console.WriteLine("average: {0}, min: {1}, max: {2}, std dev: {3}, median: {4}",
times.Average(),
times.Min(),
times.Max(),
times.StandardDeviation(),
times.Median());
var timesSansMinAndMax = new List<double>();
timesSansMinAndMax.AddRange(times);
timesSansMinAndMax.Remove(timesSansMinAndMax.Min());
timesSansMinAndMax.Remove(timesSansMinAndMax.Max());
Console.WriteLine("average sans min & max: {0}",
timesSansMinAndMax.Average());
}
示例3: Can_get_lots_of_records_with_new_instantiation_every_time_test
public void Can_get_lots_of_records_with_new_instantiation_every_time_test()
{
var times = new List<double>();
for (int i = 0; i < 40; ++i)
{
var sw = Stopwatch.StartNew();
var dapperDriver = new DapperDriver();
var rows = dapperDriver.GetLotsOfRecords<TransactionHistory>();
Assert.That(rows, Is.Not.Null);
Assert.That(rows.Count(), Is.GreaterThan(0));
sw.Stop();
times.Add(sw.ElapsedMilliseconds);
Console.WriteLine("took {0} ms to get {1} records",
sw.ElapsedMilliseconds,
rows.Count());
}
Console.WriteLine("average: {0}, min: {1}, max: {2}",
times.Average(),
times.Min(),
times.Max());
var timesSansMinAndMax = new List<double>();
timesSansMinAndMax.AddRange(times);
timesSansMinAndMax.Remove(timesSansMinAndMax.Min());
timesSansMinAndMax.Remove(timesSansMinAndMax.Max());
Console.WriteLine("average sans min & max: {0}",
timesSansMinAndMax.Average());
}
示例4: Should38
public void Should38()
{
var times = new List<long>();
var lines = File.ReadAllLines("C:\\tmp\\badphonenumber-clean.log");
foreach (var line in lines)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var isValidNumber = IsValidNumber(line.Trim());
stopwatch.Stop();
if (isValidNumber)
{
Console.WriteLine("{0}", line);
}
times.Add(stopwatch.ElapsedMilliseconds);
Thread.Sleep(TimeSpan.FromMilliseconds(500));
}
var average = times.Average();
var count = times.Count;
var sum = times.Sum();
var max = times.Max();
Console.WriteLine("{0} ms. {1} numbers. {2} sum. {3} max", average, count, sum, max);
}
示例5: Should_scale_threads_to_meet_demand
public void Should_scale_threads_to_meet_demand()
{
var now = DateTime.Now;
var latency = new List<long>();
for (int i = 0; i < 100; i++)
{
var timer = Stopwatch.StartNew();
LocalBus.Publish(new A());
Assert.IsTrue(_before.WaitOne(30.Seconds()), "Consumer thread failed to start");
timer.Stop();
latency.Add(timer.ElapsedMilliseconds);
}
Console.WriteLine("Average latency: {0}ms", latency.Average());
_wait.Set();
for (int i = 0; i < 100; i++)
{
Assert.IsTrue(_after.WaitOne(30.Seconds()), "Consumer thread failed to complete");
}
Console.WriteLine("Elapsed Time: {0}", DateTime.Now - now);
}
示例6: RunTest
public void RunTest(bool useLowLatencyBackoffStrategy, int iterations)
{
var adapter = new BuiltinContainerAdapter();
var messageHasBeenReceived = new ManualResetEvent(false);
adapter.Handle<string>(s => messageHasBeenReceived.Set());
ConfigureBus(adapter, useLowLatencyBackoffStrategy);
var bus = adapter.Bus;
var recordedLatencies = new List<TimeSpan>();
iterations.Times(() =>
{
// let things calm down
Console.Write("Calming down.... ");
Thread.Sleep(30.Seconds());
Console.Write("Sending! ");
var sendTime = DateTime.UtcNow;
bus.SendLocal("w0000tamafooook!!1");
Console.Write("waiting... ");
messageHasBeenReceived.WaitUntilSetOrDie(20.Seconds());
var elapsedUntilNow = sendTime.ElapsedUntilNow();
Console.WriteLine("got the message - recorded latency of {0}", elapsedUntilNow);
recordedLatencies.Add(elapsedUntilNow);
messageHasBeenReceived.Reset();
});
Console.WriteLine("AVERAGE RECORDED LATENCY: {0:0.00} s", recordedLatencies.Average(t => t.TotalSeconds));
}
示例7: Can_get_lots_of_records_with_new_instantiation_every_time_test
public void Can_get_lots_of_records_with_new_instantiation_every_time_test()
{
var times = new List<double>();
for (int i = 0; i < 40; ++i)
{
var sw = Stopwatch.StartNew();
var efDriver = new EFDriver();
var rows = efDriver.GetLotsOfRecords();
Assert.That(rows, Is.Not.Null);
Assert.That(rows.Count(), Is.GreaterThan(0));
sw.Stop();
times.Add(sw.ElapsedMilliseconds);
Console.WriteLine("took {0} ms to get {1} records",
sw.ElapsedMilliseconds,
rows.Count());
}
Console.WriteLine("average: {0}, min: {1}, max: {2}, std dev: {3}",
times.Average(),
times.Min(),
times.Max(),
times.StandardDeviation());
}
示例8: EmptyArray_NoIndex
public void EmptyArray_NoIndex()
{
var emptyArry = new int[0];
int x = 0;
var list = new List<double>();
//var result = 8 / x;
var result = list.Average();
// var result = question.solution(emptyArry);
Assert.AreEqual(0, 0);
}
示例9: average_LowerThenMinDouble_returnMinusInf
public void average_LowerThenMinDouble_returnMinusInf()
{
List<double> first = new List<double>();
for (int i = 0; i < 5; i++)
{
first.Add(double.MaxValue * -2);
}
a.getAverageValue(first);
Assert.AreEqual(Double.NegativeInfinity, first.Average());
}
示例10: average_MoreThenMaxDouble_returnInf
public void average_MoreThenMaxDouble_returnInf()
{
List<double> first = new List<double>();
for (int i = 0; i < 5; i++)
{
first.Add(double.MaxValue*2);
}
a.getAverageValue(first);
Assert.AreEqual(Double.PositiveInfinity, first.Average());
}
示例11: average_NormalPositiveValues_returnCorrectValue
public void average_NormalPositiveValues_returnCorrectValue()
{
List<double> first = new List<double>();
for(int i = 0; i < 5; i++)
{
first.Add(i * 10);
}
double expected = 20.0;
a.getAverageValue(first);
Assert.AreEqual(expected, first.Average());
}
示例12: getting_stack_overflow
public void getting_stack_overflow()
{
var l = new List<Stopwatch>();
for (var i = 0; i < 10000; i++)
{
var w = Stopwatch.StartNew();
PathInfo.Parse("C:");
w.Stop();
l.Add(w);
}
Console.WriteLine("mean time: {0}", l.Average(x => x.ElapsedTicks));
}
示例13: DumpHistory
private static void DumpHistory(List<EodPoint> download)
{
Console.WriteLine("Assert.AreEqual({0}, download.Count);", download.Count);
Console.WriteLine("Assert.IsTrue(download.All(x => x.High >= x.Low));");
Console.WriteLine("Assert.AreEqual({0}m, download.Average(x => x.{1}));", download.Average(x => x.Adj_Close).ToString(CultureInfo.InvariantCulture), "Adj_Close");
Console.WriteLine("Assert.AreEqual({0}m, download.Average(x => x.{1}));", download.Average(x => x.Close).ToString(CultureInfo.InvariantCulture), "Close");
Console.WriteLine("Assert.AreEqual({0}m, download.Average(x => x.{1}));", download.Average(x => x.High).ToString(CultureInfo.InvariantCulture), "High");
Console.WriteLine("Assert.AreEqual({0}m, download.Average(x => x.{1}));", download.Average(x => x.Low).ToString(CultureInfo.InvariantCulture), "Low");
Console.WriteLine("Assert.AreEqual({0}m, download.Average(x => x.{1}));", download.Average(x => x.Open).ToString(CultureInfo.InvariantCulture), "Open");
Console.WriteLine("Assert.AreEqual({0}, download.Average(x => x.{1}), 1);", download.Average(x => x.Volume).ToString(CultureInfo.InvariantCulture), "Volume");
}
示例14: AnalyseConditionalCopySpeed
public void AnalyseConditionalCopySpeed()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var timings = new List<long>
{
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
RunConditionalCopy(BuildAndMeasureTree(stopwatch), stopwatch),
};
timings.Average().Should().BeLessOrEqualTo(100);
}
示例15: FilterLargeGraphSpeed
public void FilterLargeGraphSpeed()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var timings = new List<long>
{
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
RunFilter(BuildAndMeasureTree(stopwatch), stopwatch),
};
timings.Average().Should().BeLessOrEqualTo(100);
}