예제 #1
0
        public void TestCacheSizeFour()
        {
            var fifoAlgorithm = new FifoAlgorithm(4);

            Assert.AreEqual(5, fifoAlgorithm.HandleSequence("abcbadce"));
            Assert.AreEqual(6, fifoAlgorithm.HandleSingleInput('f'));
            Assert.AreEqual(7, fifoAlgorithm.HandleSingleInput('a'));

            fifoAlgorithm = new FifoAlgorithm(4);

            Assert.AreEqual(1, fifoAlgorithm.HandleSingleInput('a'));
            Assert.AreEqual(2, fifoAlgorithm.HandleSingleInput('b'));
            Assert.AreEqual(3, fifoAlgorithm.HandleSingleInput('c'));
            Assert.AreEqual(4, fifoAlgorithm.HandleSingleInput('d'));
            Assert.AreEqual(4, fifoAlgorithm.HandleSingleInput('a'));
            Assert.AreEqual(4, fifoAlgorithm.HandleSingleInput('b'));
            Assert.AreEqual(5, fifoAlgorithm.HandleSingleInput('e'));
            Assert.AreEqual(6, fifoAlgorithm.HandleSingleInput('a'));
            Assert.AreEqual(7, fifoAlgorithm.HandleSingleInput('b'));
            Assert.AreEqual(8, fifoAlgorithm.HandleSingleInput('c'));
            Assert.AreEqual(9, fifoAlgorithm.HandleSingleInput('d'));
            Assert.AreEqual(10, fifoAlgorithm.HandleSingleInput('e'));
        }
        public SingleSequenceBenchmarkResult RunBenchmarkForAllAlgorithms()
        {
            var result = new SingleSequenceBenchmarkResult(CacheSize,
                                                           SequenceSizeMultiplier, DistinctPagesCount);

            for (int i = 0; i < InputSequence.Length; i++)
            {
                var currentInput = InputSequence[i];

                if (LargerFifoAlgorithm.HandleSingleInput(currentInput) >
                    FifoAlgorithm.HandleSingleInput(currentInput))
                {
                    result.FifoAnomalyCount++;
                }

                if (LargerFifo2Algorithm.HandleSingleInput(currentInput) >
                    Fifo2Algorithm.HandleSingleInput(currentInput))
                {
                    result.Fifo2AnomalyCount++;
                }

                if (LargerLruAlgorithm.HandleSingleInput(currentInput) >
                    LruAlgorithm.HandleSingleInput(currentInput))
                {
                    result.LruAnomalyCount++;
                }

                if (LargerLru2Algorithm.HandleSingleInput(currentInput) >
                    Lru2Algorithm.HandleSingleInput(currentInput))
                {
                    result.Lru2AnomalyCount++;
                }

                if (LargerMruAlgorithm.HandleSingleInput(currentInput) >
                    MruAlgorithm.HandleSingleInput(currentInput))
                {
                    result.MruAnomalyCount++;
                }

                if (LargerBitPlruAlgorithm.HandleSingleInput(currentInput) >
                    BitPlruAlgorithm.HandleSingleInput(currentInput))
                {
                    result.BitPlruAnomalyCount++;
                }

                if (LargerFwfAlgorithm.HandleSingleInput(currentInput) >
                    FwfAlgorithm.HandleSingleInput(currentInput))
                {
                    result.FwfAnomalyCount++;
                }

                if (LargerLifoAlgorithm.HandleSingleInput(currentInput) >
                    LifoAlgorithm.HandleSingleInput(currentInput))
                {
                    result.LifoAnomalyCount++;
                }

                {
                    var largerPreviousRandomNumbersCount = LargerUniformRandomPageAlgorithm.
                                                           RandomNumbers.Count;

                    var largerUniformRandomPageCost = LargerUniformRandomPageAlgorithm.
                                                      HandleSingleInput(currentInput);

                    if (LargerUniformRandomPageAlgorithm.RandomNumbers.Count >
                        largerPreviousRandomNumbersCount)
                    {
                        UniformRandomPageAlgorithm.RandomNumbers.Add(
                            LargerUniformRandomPageAlgorithm.RandomNumbers.Last());

                        Debug.Assert(UniformRandomPageAlgorithm.RandomNumbers.Count ==
                                     LargerUniformRandomPageAlgorithm.RandomNumbers.Count,
                                     "Error in retaining random numbers between two algorithms.");
                    }

                    var previousRandomNumbersCount = UniformRandomPageAlgorithm.
                                                     RandomNumbers.Count;

                    var uniformRandomPageCost = UniformRandomPageAlgorithm.HandleSingleInput(currentInput);

                    if (UniformRandomPageAlgorithm.RandomNumbers.Count >
                        previousRandomNumbersCount)
                    {
                        LargerUniformRandomPageAlgorithm.RandomNumbers.Add(
                            UniformRandomPageAlgorithm.RandomNumbers.Last());

                        Debug.Assert(UniformRandomPageAlgorithm.RandomNumbers.Count ==
                                     LargerUniformRandomPageAlgorithm.RandomNumbers.Count,
                                     "Error in retaining random numbers between two algorithms.");
                    }

                    if (largerUniformRandomPageCost > uniformRandomPageCost)
                    {
                        result.UniformRandomPageAnomalyCount++;
                    }
                }
            }

            result.FifoCost       = FifoAlgorithm.CurrentCost;
            result.LargerFifoCost = LargerFifoAlgorithm.CurrentCost;

            result.Fifo2Cost       = Fifo2Algorithm.CurrentCost;
            result.LargerFifo2Cost = LargerFifo2Algorithm.CurrentCost;

            result.LruCost       = LruAlgorithm.CurrentCost;
            result.LargerLruCost = LargerLruAlgorithm.CurrentCost;

            result.Lru2Cost       = Lru2Algorithm.CurrentCost;
            result.LargerLru2Cost = LargerLru2Algorithm.CurrentCost;

            result.BitPlruCost       = BitPlruAlgorithm.CurrentCost;
            result.LargerBitPlruCost = LargerBitPlruAlgorithm.CurrentCost;

            result.MruCost       = MruAlgorithm.CurrentCost;
            result.LargerMruCost = LargerMruAlgorithm.CurrentCost;

            result.LifoCost       = LifoAlgorithm.CurrentCost;
            result.LargerLifoCost = LargerLifoAlgorithm.CurrentCost;

            result.FwfCost       = FwfAlgorithm.CurrentCost;
            result.LargerFwfCost = LargerFwfAlgorithm.CurrentCost;

            result.UniformRandomPageCost       = UniformRandomPageAlgorithm.CurrentCost;
            result.LargerUniformRandomPageCost = LargerUniformRandomPageAlgorithm.CurrentCost;

            return(result);
        }
예제 #3
0
        public void TestCacheSizeThree()
        {
            var fifoAlgorithm = new FifoAlgorithm(3);

            Assert.AreEqual(1, fifoAlgorithm.HandleSingleInput('a'));
            Assert.AreEqual(2, fifoAlgorithm.HandleSingleInput('b'));
            Assert.AreEqual(3, fifoAlgorithm.HandleSingleInput('c'));
            Assert.AreEqual(4, fifoAlgorithm.HandleSingleInput('d'));
            Assert.AreEqual(5, fifoAlgorithm.HandleSingleInput('a'));
            Assert.AreEqual(6, fifoAlgorithm.HandleSingleInput('b'));
            Assert.AreEqual(7, fifoAlgorithm.HandleSingleInput('e'));
            Assert.AreEqual(7, fifoAlgorithm.HandleSingleInput('a'));
            Assert.AreEqual(7, fifoAlgorithm.HandleSingleInput('b'));
            Assert.AreEqual(8, fifoAlgorithm.HandleSingleInput('c'));
            Assert.AreEqual(9, fifoAlgorithm.HandleSingleInput('d'));
            Assert.AreEqual(9, fifoAlgorithm.HandleSingleInput('e'));
        }