Histogram for tracking the frequency of observations of values below interval upper bounds. This class is useful for recording timings in nanoseconds across a large number of observations when high performance is required.
示例#1
0
        public void ShouldAddObservations()
        {
            AddObservations(_histogram, 10L, 30L, 50L);

            var histogram2 = new Histogram(Intervals);
            AddObservations(histogram2, 10L, 20L, 25L);

            _histogram.AddObservations(histogram2);

            Assert.AreEqual(6L, _histogram.Count);
        }
示例#2
0
        public void ShouldCorrectMeanForSkewInTopAndBottomPopulatedIntervals()
        {
            var intervals = new long[]{ 100, 110, 120, 130, 140, 150, 1000, 10000 };
            var histogram = new Histogram(intervals);

            for (long i = 100; i < 152; i++)
            {
                histogram.AddObservation(i);
            }

            Assert.AreEqual(125.02d, histogram.Mean);
        }
 public LatencyStepQueueEventProcessor(FunctionStep functionStep,
                             BlockingCollection<long> inputQueue,
                             BlockingCollection<long> outputQueue,
                             Histogram histogram, long nanoTimeCost, double ticksToNanos, long iterations)
 {
     _functionStep = functionStep;
     _inputQueue = inputQueue;
     _outputQueue = outputQueue;
     _histogram = histogram;
     _nanoTimeCost = nanoTimeCost;
     _ticksToNanos = ticksToNanos;
     _iterations = iterations;
 }
	    public LatencyStepQueueConsumer(FunctionStep functionStep,
	                                    BlockingCollection<long> inputQueue,
	                                    BlockingCollection<long> outputQueue,
	                                    Histogram histogram, 
	                                    long nanoTimeCost,
	                                   Stopwatch stopwatch)
	    {
	        this.functionStep = functionStep;
	        this.inputQueue = inputQueue;
	        this.outputQueue = outputQueue;
	        this.histogram = histogram;
	        this.nanoTimeCost = nanoTimeCost;
	        this.stopwatch = stopwatch;
	    }
示例#5
0
        /// <summary>
        /// Add observations from another Histogram into this one.
        /// Histograms must have the same intervals.
        /// </summary>
        /// <param name="histogram">histogram from which to add the observation counts.</param>
        public void AddObservations(Histogram histogram)
        {
            if (_upperBounds.Length != histogram._upperBounds.Length)
            {
                throw new ArgumentException("Histograms must have matching intervals", "histogram");
            }

            for (int i = 0; i < _upperBounds.Length; i++)
            {
                if (_upperBounds[i] != histogram._upperBounds[i])
                {
                    throw new ArgumentException("Histograms must have matching intervals", "histogram");
                }
            }

            for (int i = 0; i < _counts.Length; i++)
            {
                _counts[i] += histogram._counts[i];
            }

            TrackRange(histogram._minValue);
            TrackRange(histogram._maxValue);
        }
        private void InitHistogram()
        {

            if (_histogram == null)
            {
                var intervals = new long[31];
                var intervalUpperBound = 1L;
                for (var i = 0; i < intervals.Length - 1; i++)
                {
                    intervalUpperBound *= 2;
                    intervals[i] = intervalUpperBound;
                }

                intervals[intervals.Length - 1] = long.MaxValue;
                _histogram = new Histogram(intervals);
            }
        }
		private void InitHistogram()
		{
			long[] intervals = new long[31];
			long intervalUpperBound = 1L;
			for (int i = 0, size = intervals.Length - 1; i < size; i++)
			{
				intervalUpperBound *= 2;
				intervals[i] = intervalUpperBound;
			}

			intervals[intervals.Length - 1] = long.MaxValue;
			_histogram = new Histogram(intervals);
		}
示例#8
0
        public void ShouldGetFourNinesUpperBound()
        {
            var intervals = new long[]{ 1, 10, 100, 1000, 10000 };
            var histogram = new Histogram(intervals);

            for (long i = 1; i < 102; i++)
            {
                histogram.AddObservation(i);
            }

            Assert.AreEqual(1000L, histogram.FourNinesUpperBound);
        }
示例#9
0
 public void SetUp()
 {
     _histogram = new Histogram(Intervals);
 }
示例#10
0
 private static void AddObservations(Histogram histogram, params long[] observations)
 {
     foreach (var observation in observations)
     {
         histogram.AddObservation(observation);
     }
 }
示例#11
0
 public void ShouldThrowExceptionWhenIntervalsDoNotMatch()
 {
     var histogram2 = new Histogram(new[]{ 1L, 2L, 3L});
     _histogram.AddObservations(histogram2);
 }
示例#12
0
 public void ShouldNotAddObservation()
 {
     var histogram = new Histogram(new long[]{ 10, 20, 30 });
     Assert.IsFalse(histogram.AddObservation(31L));
 }
示例#13
0
        public void ShouldGetMeanObservation()
        {
            var intervals = new long[]{ 1, 10, 100, 1000, 10000 };
            var histogram = new Histogram(intervals);

            AddObservations(histogram, 1L, 7L, 10L, 10L, 11L, 144L);

            Assert.AreEqual(32.67d, histogram.Mean);
        }