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.
Exemplo n.º 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);
        }
Exemplo n.º 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;
	    }
Exemplo n.º 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);
		}
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 public void SetUp()
 {
     _histogram = new Histogram(Intervals);
 }
Exemplo n.º 10
0
 private static void AddObservations(Histogram histogram, params long[] observations)
 {
     foreach (var observation in observations)
     {
         histogram.AddObservation(observation);
     }
 }
Exemplo n.º 11
0
 public void ShouldThrowExceptionWhenIntervalsDoNotMatch()
 {
     var histogram2 = new Histogram(new[]{ 1L, 2L, 3L});
     _histogram.AddObservations(histogram2);
 }
Exemplo n.º 12
0
 public void ShouldNotAddObservation()
 {
     var histogram = new Histogram(new long[]{ 10, 20, 30 });
     Assert.IsFalse(histogram.AddObservation(31L));
 }
Exemplo n.º 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);
        }