Пример #1
0
 private static void AssertDefinition(SampleGroup sampleGroup, string name, SampleUnit sampleUnit,
                                      bool increaseIsBetter)
 {
     Assert.AreEqual(sampleGroup.Name, name);
     Assert.AreEqual(sampleGroup.Unit, sampleUnit);
     Assert.AreEqual(sampleGroup.IncreaseIsBetter, increaseIsBetter);
 }
Пример #2
0
    public void MeasureCustom_SampleGroup_CorrectValues()
    {
        SampleGroup sg = new SampleGroup("REGULAR", SampleUnit.Byte, true);

        Measure.Custom(sg, 10D);

        var test = PerformanceTest.Active;

        Assert.AreEqual(test.SampleGroups.Count, 1);
        Assert.AreEqual(test.SampleGroups[0].Samples.Count, 1);
        Assert.AreEqual(test.SampleGroups[0].Samples[0], 10D, 0.001D);
        AssertDefinition(test.SampleGroups[0], "REGULAR", SampleUnit.Byte, true);
    }
Пример #3
0
    public void MeasureCustom_PercentileSample_CorrectValues()
    {
        SampleGroup sg = new SampleGroup("PERCENTILE", SampleUnit.Second, true);

        Measure.Custom(sg, 10D);

        var test = PerformanceTest.Active;

        Assert.AreEqual(test.SampleGroups.Count, 1);
        Assert.AreEqual(test.SampleGroups[0].Samples.Count, 1);
        Assert.AreEqual(test.SampleGroups[0].Samples[0], 10D, 0.001D);
        AssertDefinition(test.SampleGroups[0], "PERCENTILE", SampleUnit.Second, true);
    }
Пример #4
0
    public void MeasureScope_WithSampleGroup_ResultsIsInTheDefinedSampleUnit()
    {
        var sg = new SampleGroup("TEST", SampleUnit.Microsecond);

        using (Measure.Scope(sg))
        {
        }

        var result = PerformanceTest.Active;

        Assert.AreEqual(1, result.SampleGroups.Count);
        AssertDefinition(result.SampleGroups[0], sg.Name, sg.Unit, increaseIsBetter: false);
    }
Пример #5
0
    public void MeasureCustom_MultipleSampleGroups()
    {
        SampleGroup sg  = new SampleGroup("REGULAR", SampleUnit.Byte, true);
        SampleGroup sg2 = new SampleGroup("PERCENTILE", SampleUnit.Second, true);

        Measure.Custom(sg, 20D);
        Measure.Custom(sg2, 10D);

        var test = PerformanceTest.Active;

        Assert.AreEqual(test.SampleGroups.Count, 2);
        AssertDefinition(test.SampleGroups[0], "REGULAR", SampleUnit.Byte, true);
        AssertDefinition(test.SampleGroups[1], "PERCENTILE", SampleUnit.Second, true);
    }
    public void MeasureCustom_PercentileSamples_CorrectValues()
    {
        var sg = new SampleGroup("PERCENTILE", SampleUnit.Second, increaseIsBetter: true);

        Measure.Custom(sg, 10D);
        Measure.Custom(sg, 20D);

        var test = PerformanceTest.Active;

        Assert.AreEqual(1, test.SampleGroups.Count);
        Assert.AreEqual(2, test.SampleGroups[0].Samples.Count);
        Assert.AreEqual(10D, test.SampleGroups[0].Samples[0], 0.001D);
        Assert.AreEqual(20D, test.SampleGroups[0].Samples[1], 0.001D);
        AssertDefinition(test.SampleGroups[0], "PERCENTILE", SampleUnit.Second, increaseIsBetter: true);
    }
    public void MeasureCustom_SampleGroupWithSamples_CorrectValues()
    {
        var sg = new SampleGroup("REGULAR", SampleUnit.Byte, true);

        Measure.Custom(sg, 10D);
        Measure.Custom(sg, 20D);

        var test = PerformanceTest.Active;

        Assert.AreEqual(1, test.SampleGroups.Count);
        Assert.AreEqual(2, test.SampleGroups[0].Samples.Count);
        Assert.AreEqual(10D, test.SampleGroups[0].Samples[0], 0.001D);
        Assert.AreEqual(20D, test.SampleGroups[0].Samples[1], 0.001D);
        AssertDefinition(test.SampleGroups[0], "REGULAR", SampleUnit.Byte, increaseIsBetter: true);
    }
Пример #8
0
        public static void Custom(string name, double value)
        {
            if (double.IsNaN(value))
            {
                throw new PerformanceTestException(
                          $"Trying to record value which is not a number for sample group: {name}");
            }

            var sg = PerformanceTest.GetSampleGroup(name);

            if (sg == null)
            {
                sg = new SampleGroup(name);
                PerformanceTest.Active.SampleGroups.Add(sg);
            }

            sg.Samples.Add(value);
        }
Пример #9
0
        private static double?GetAggregationValue(SampleGroup sampleGroup)
        {
            switch (sampleGroup.Definition.AggregationType)
            {
            case AggregationType.Average:
                return(sampleGroup.Average);

            case AggregationType.Min:
                return(sampleGroup.Min);

            case AggregationType.Max:
                return(sampleGroup.Max);

            case AggregationType.Median:
                return(sampleGroup.Median);

            case AggregationType.Percentile:
                return(sampleGroup.PercentileValue);

            default:
                throw new ArgumentOutOfRangeException("sampleGroup");
            }
        }
Пример #10
0
 public static ScopeMeasurement Scope(SampleGroup sampleGroup)
 {
     return(new ScopeMeasurement(sampleGroup));
 }
Пример #11
0
 public ScopeMeasurement(SampleGroupDefinition sampleGroupDefinition)
 {
     m_TimeSampleGroup = new SampleGroup(sampleGroupDefinition);
     m_StartTicks      = Stopwatch.GetTimestamp();
     PerformanceTest.Disposables.Add(this);
 }
Пример #12
0
    public void MeasureCustom_NaN_Throws()
    {
        SampleGroup sg = new SampleGroup("REGULAR", SampleUnit.Byte, true);

        Assert.Throws <PerformanceTestException>(() => Measure.Custom(sg, double.NaN));
    }
Пример #13
0
 public static void AddSampleGroup(SampleGroup sampleGroup)
 {
     Active.SampleGroups.Add(sampleGroup);
 }