def simple_test_arc(self):
     c = AdaptiveReplacementCache(4)
     self.assertEquals(c.get_p(), 0)
     c.put(0)
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(len(c), 1)
     c.put(2)
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(len(c), 2)
     c.put(3)
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(len(c), 3)
     c.put(4)
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(len(c), 4)
     self.assertEquals(c.dump(), [4, 3, 2, 0])
     # last element in top of recency cache is put into bottom
     self.assertEquals(c.put(5), 0)
     self.assertEquals(c.get_p(), 0)
     # 5 moves to frequency cache
     self.assertEquals(c.put(5), None)
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(len(c), 4)
     self.assertEquals(c.dump(), [5, 4, 3, 2])
     # put 2 into frequency cache
     c.get(2)
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(c.dump(), [2, 5, 4, 3])
     # put 4 into frequency cache
     c.get(4)
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(c.dump(), [4, 2, 5, 3])
     c.clear()
     self.assertEquals(c.get_p(), 0)
     self.assertEquals(len(c), 0)
     self.assertEquals(c.dump(), [])
Ejemplo n.º 2
0
 def simple_test_arc(self):
     c = AdaptiveReplacementCache(4)
     self.assertEqual(c.get_p(), 0)
     c.put(0)
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(len(c), 1)
     c.put(2)
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(len(c), 2)
     c.put(3)
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(len(c), 3)
     c.put(4)
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(len(c), 4)
     self.assertEqual(c.dump(), [4, 3, 2, 0])
     # last element in top of recency cache is put into bottom
     self.assertEqual(c.put(5), 0)
     self.assertEqual(c.get_p(), 0)
     # 5 moves to frequency cache
     self.assertEqual(c.put(5), None)
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(len(c), 4)
     self.assertEqual(c.dump(), [5, 4, 3, 2])
     # put 2 into frequency cache
     c.get(2)
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(c.dump(), [2, 5, 4, 3])
     # put 4 into frequency cache
     c.get(4)
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(c.dump(), [4, 2, 5, 3])
     c.clear()
     self.assertEqual(c.get_p(), 0)
     self.assertEqual(len(c), 0)
     self.assertEqual(c.dump(), [])
    def test_arc_fastly(self):
        import csv

        c = AdaptiveReplacementCache(100)
        cache_hits = 0
        contents = 0

        with open("../../../resources/Fastly_traces/requests_14M-2015-12-1_reformatted.trace", "r") as csv_file:
            csv_reader = csv.reader(csv_file)
            for row in csv_reader:
                contents += 1
                content = int(row[2])

                if c.get(content):
                    cache_hits += 1
                else:
                    c.put(content)

                if contents % 100000 == 0:
                    print contents, 14885146, float(contents) / float(14885146)

        self.assertEquals([contents, cache_hits], [14885146, 2679672])
Ejemplo n.º 4
0
    def test_arc_fastly(self):
        import csv
        c = AdaptiveReplacementCache(100)
        cache_hits = 0
        contents = 0

        with open(
                '../../../resources/Fastly_traces/requests_14M-2015-12-1_reformatted.trace',
                'r') as csv_file:
            csv_reader = csv.reader(csv_file)
            for row in csv_reader:
                contents += 1
                content = int(row[2])

                if c.get(content):
                    cache_hits += 1
                else:
                    c.put(content)

                if contents % 100000 == 0:
                    print(contents, 14885146,
                          float(contents) / float(14885146))

        self.assertEqual([contents, cache_hits], [14885146, 2679672])