< Summary

Class:DCL.BenchmarkResult
Assembly:PerformanceMeterController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/Performance/PerformanceMeterController/BenchmarkResult.cs
Covered lines:0
Uncovered lines:26
Coverable lines:26
Total lines:77
Line coverage:0% (0 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BenchmarkResult()0%2100%
BenchmarkResult(...)0%2100%
SetSamples(...)0%12300%
Variance(...)0%6200%
StdDev(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/Performance/PerformanceMeterController/BenchmarkResult.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5namespace DCL
 6{
 7    [Serializable]
 8    public class BenchmarkResult
 9    {
 10        // metrics based on this // https://github.com/bestiejs/benchmark.js/blob/master/benchmark.js#L1912
 11        private const double T_TABLE_INFINITY = 1.96;
 012        private static readonly IReadOnlyDictionary<int, double> tTable = new Dictionary<int, double>()
 13        {
 14            { 01, 12.706 }, { 02, 4.303 }, { 03, 3.182 },
 15            { 04, 02.776 }, { 05, 2.571 }, { 06, 2.447 },
 16            { 07, 02.365 }, { 08, 2.306 }, { 09, 2.262 },
 17            { 10, 02.228 }, { 11, 2.201 }, { 12, 2.179 },
 18            { 13, 02.160 }, { 14, 2.145 }, { 15, 2.131 },
 19            { 16, 02.120 }, { 17, 2.110 }, { 18, 2.101 },
 20            { 19, 02.093 }, { 20, 2.086 }, { 21, 2.080 },
 21            { 22, 02.074 }, { 23, 2.069 }, { 24, 2.064 },
 22            { 25, 02.060 }, { 26, 2.056 }, { 27, 2.052 },
 23            { 28, 02.048 }, { 29, 2.045 }, { 30, 2.042 }
 24        };
 25
 26        public double min;
 27        public double max;
 28        public double moe; // Margin of error
 29        public double rme = 0; // Relative Margin of Error
 30        public double sem; // Mean standard error
 31        public double stdDev;
 32        public double mean;
 33        public double variance;
 34        private double[] samples;
 35
 036        public BenchmarkResult(double[] samples)
 37        {
 038            SetSamples(samples);
 039        }
 40
 41        // Note (Kinerius): This code is lazy and performs poorly, please optimize if used outside our debugging tools
 42        public void SetSamples(double[] samples)
 43        {
 044            this.samples = samples;
 045            int sampleSize = samples.Length;
 46
 047            min = samples.Min();
 048            max = samples.Max();
 049            mean = samples.Average();
 050            variance = Variance(samples);
 051            stdDev = StdDev(variance);
 052            sem = stdDev / Math.Sqrt(sampleSize);
 53            // Compute the degrees of freedom.
 054            int df = sampleSize - 1;
 55            // Compute the critical value.
 056            int tTableIndex = Math.Max(df, 1); //Minimum index is 1;
 057            if (!tTable.TryGetValue(tTableIndex, out double critical))
 058                critical = T_TABLE_INFINITY; // we take the infinity
 59
 060            moe = sem * critical;
 061            if (mean != 0)
 062                rme = (moe / mean) * 100;
 063        }
 64
 65        private static double Variance(double[] samples)
 66        {
 067            if (samples.Length <= 1)
 068                return 0.0;
 69
 070            double avg = samples.Average();
 071            double variance = samples.Sum(value => (value - avg) * (value - avg));
 072            return variance / samples.Length;
 73        }
 74
 075        private static double StdDev(double variance) { return Math.Sqrt(variance); }
 76    }
 77}