Example #1
0
        public static TimingPercentileStats CalculateSomePercentiles(long[] timingArr)
        {
            var stats = new TimingPercentileStats()
            {
                Time      = DateTime.Now,
                Centile   = new int[] { -50, 1 },
                AvgTiming = new long[2]
            };

            for (int i = 0; i < stats.Centile.Length; i++)
            {
                if (stats.Centile[i] < 0)
                {
                    int lowestXPctNum = (timingArr.Length * -1 * stats.Centile[i]) / 100;
                    if (lowestXPctNum != 0)
                    {
                        stats.AvgTiming[i] = timingArr.OrderBy(t1 => t1).Take(lowestXPctNum).Sum(t2 => t2) / lowestXPctNum;
                    }
                }
                else
                {
                    int topXPctNum = (timingArr.Length * stats.Centile[i]) / 100;
                    if (topXPctNum != 0)
                    {
                        stats.AvgTiming[i] = timingArr.OrderByDescending(t1 => t1).Take(topXPctNum).Sum(t2 => t2) / topXPctNum;
                    }
                }
            }

            return(stats);
        }
Example #2
0
        public static TimingPercentileStats CalculateSomePercentiles(long[] timingArr)
        {
            var stats = new TimingPercentileStats()
            {
                Time      = DateTime.Now,
                Centile   = new int[] { -50, 1 },
                AvgTiming = new long[2]
            };

            for (int i = 0; i < stats.Centile.Length; i++)
            {
                if (stats.Centile[i] < 0)
                {
                    int lowestXPctNum = (timingArr.Length * -1 * stats.Centile[i]) / 100;
                    stats.AvgTiming[i] = timingArr.OrderBy(t1 => t1).Take(lowestXPctNum).Sum(t2 => t2) / lowestXPctNum;
                }
                else
                {
                    int topXPctNum = (timingArr.Length * stats.Centile[i]) / 100;
                    stats.AvgTiming[i] = timingArr.OrderByDescending(t1 => t1).Take(topXPctNum).Sum(t2 => t2) / topXPctNum;
                }

                //Console.WriteLine(String.Format("Percentile {0}, time {1}", stats.Centile[i], stats.AvgTiming[i]));
            }

            return(stats);
        }