Esempio n. 1
0
 /// <summary>
 /// Stops the timer and adds a specified timing point type to th timings list
 /// </summary>
 /// <param name="timerType"></param>
 /// <returns></returns>
 public TimeSpan StopTimer(EnumTiming timerType)
 {
     try
     {
         CurrentTimer.Stop();
         Timings.Add(new Tuple <EnumTiming, RatTimer>(timerType, CurrentTimer));
         return(CurrentTimer.Duration);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Unable to stop the timer");
         Console.WriteLine(ex.Message);
         return(new TimeSpan(0));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// The variance of the timings list sample
        /// </summary>
        /// <param name="enumTiming">Type of timing point</param>
        /// <returns>How far the timings list values are spread out from the mean</returns>
        public double Variance([DefaultParameterValue(EnumTiming.NotSpecified)] EnumTiming enumTiming)
        {
            try
            {
                IEnumerable <double> valueList =
                    Timings.Where(v => v.Item1 == enumTiming)
                    .DefaultIfEmpty()
                    .Select(v => v.Item2.Duration.TotalMilliseconds);

                return(Statistics.Variance(valueList));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to calculate the variance of the sample");
                Console.WriteLine(ex.Message);
                return(0d);
            }
        }