Esempio n. 1
0
        public void testGetEstimatedFootprintInBytes()
        {
            Histogram histogram = new Histogram(highestTrackableValue, numberOfSignificantValueDigits);

            /*
             *     largestValueWithSingleUnitResolution = 2 * (10 ^ numberOfSignificantValueDigits);
             *     subBucketSize = roundedUpToNearestPowerOf2(largestValueWithSingleUnitResolution);
             *
             *     expectedHistogramFootprintInBytes = 512 +
             *          ({primitive type size} / 2) *
             *          (log2RoundedUp((highestTrackableValue) / subBucketSize) + 2) *
             *          subBucketSize
             */
            long largestValueWithSingleUnitResolution = 2 * (long)Math.Pow(10, numberOfSignificantValueDigits);
            int  subBucketCountMagnitude = (int)Math.Ceiling(Math.Log(largestValueWithSingleUnitResolution) / Math.Log(2));
            int  subBucketSize           = (int)Math.Pow(2, (subBucketCountMagnitude));

            long expectedSize = 512 +
                                ((8 *
                                  ((long)(
                                       Math.Ceiling(
                                           Math.Log(highestTrackableValue / subBucketSize)
                                           / Math.Log(2)
                                           )
                                       + 2)) *
                                  (1 << (64 - MiscUtilities.numberOfLeadingZeros(2 * (long)Math.Pow(10, numberOfSignificantValueDigits))))
                                  ) / 2);

            Assert.assertEquals(expectedSize, histogram.getEstimatedFootprintInBytes());
        }
Esempio n. 2
0
        long LeadingZerosSpeedLoop(long loopCount)
        {
            long sum = 0;

            for (long i = 0; i < loopCount; i++)
            {
                // long val = testValueLevel + (i & 0x8000);
                long val = testValueLevel;
                sum += MiscUtilities.numberOfLeadingZeros(val);
                sum += MiscUtilities.numberOfLeadingZeros(val);
                sum += MiscUtilities.numberOfLeadingZeros(val);
                sum += MiscUtilities.numberOfLeadingZeros(val);
                sum += MiscUtilities.numberOfLeadingZeros(val);
                sum += MiscUtilities.numberOfLeadingZeros(val);
                sum += MiscUtilities.numberOfLeadingZeros(val);
                sum += MiscUtilities.numberOfLeadingZeros(val);
            }
            return(sum);
        }
Esempio n. 3
0
 public void testnumberOfLeadingZeros(long numberToTest)
 {
     Assert.AreEqual(numberOfLeadingZerosSLOW(numberToTest), MiscUtilities.numberOfLeadingZeros(numberToTest));
 }