Example #1
0
        public void SuccessRate(int iterations, double successRate)
        {
            var fickleTimes = MethodTimer.MeasureExecution(() => FickleFunc(successRate), iterations);

            Asserter.Against(fickleTimes)
            .And(Has.Property(nameof(fickleTimes.SuccessRate)).CloseTo(successRate, 0.005))
            .And(Has.Property(nameof(fickleTimes.Iterations)).EqualTo(iterations))
            .Invoke();
        }
Example #2
0
        public void ListVsSet()
        {
            const int iterations = 1000;
            var       items      = MakeHugeCollection(iterations).ToArray();
            var       toFind     = items.Random();

            // Using their respecting .Contains() methods

            var list = items.ToList();
            var set  = items.ToHashSet();

            var listTimes = MethodTimer.MeasureExecution(() => ListContains(list, toFind), iterations);
            var setTimes  = MethodTimer.MeasureExecution(() => SetContains(set, toFind), iterations);

            Console.WriteLine($"list: {listTimes}");
            Console.WriteLine($"set:  {setTimes}");

            // Using the extension Enumerable.Contains()

            list.RandomizeEntries();
            set.RandomizeEntries();

            var listableTimes = MethodTimer.MeasureExecution(() => EnumerableContains(list, toFind), iterations);
            var settableTimes = MethodTimer.MeasureExecution(() => EnumerableContains(set, toFind), iterations);

            Console.WriteLine($"{nameof(listableTimes)}: {listableTimes}");
            Console.WriteLine($"{nameof(settableTimes)}: {settableTimes}");

            // Actually doing a comparison
            var comparison = new AggregateExecutionComparison(listTimes, setTimes);

            Console.WriteLine(comparison);
            Asserter.Against(comparison)
            .And(AssertComparison(comparison.Average, 1))
            .And(AssertComparison(comparison.Total, 1))
            .Invoke();
        }