Esempio n. 1
0
        public static IEnumerable <PerformanceData> GetResults()
        {
            var timingGroups = _timingLookupInstance.Values.SelectMany(lookup => lookup.Values).GroupBy(meas => meas.Name);

            foreach (var timingGroup in timingGroups)
            {
                PerformanceData data = new PerformanceData(timingGroup.Key);
                data.Count   = timingGroup.Sum(meas => meas.Count);
                data.Average = timingGroup.Average(meas => meas.Average);
                data.Min     = timingGroup.Min(meas => meas.Average);
                data.Max     = timingGroup.Max(meas => meas.Average);
                yield return(data);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Records a response time in milliseconds for the given name.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="milliseconds"></param>
        public static void Add(string name, long milliseconds)
        {
            Dictionary <string, PerformanceData> lookup = _timingLookupInstance.Value;

            PerformanceData data;

            if (!lookup.TryGetValue(name, out data))
            {
                data = new PerformanceData(name);
                lookup.Add(name, data);
            }

            if (data.Count == 0)
            {
                data.Average = milliseconds;
                data.Min     = milliseconds;
                data.Max     = milliseconds;
                data.Count++;
            }
            else
            {
                // calculate average
                data.Average = ((data.Average * data.Count) + milliseconds) / (data.Count + 1);

                // check min
                if (milliseconds < data.Min)
                {
                    data.Min = milliseconds;
                }

                // check max
                if (milliseconds > data.Max)
                {
                    data.Max = milliseconds;
                }

                data.Count++;
            }
        }