private void TestCache(DoubleBarrelLRUCache <CloneableInteger, object> cache, int n) { object dummy = new object(); for (int i = 0; i < n; i++) { cache.Put(new CloneableInteger(i), dummy); } // access every 2nd item in cache for (int i = 0; i < n; i += 2) { Assert.IsNotNull(cache.Get(new CloneableInteger(i))); } // add n/2 elements to cache, the ones that weren't // touched in the previous loop should now be thrown away for (int i = n; i < n + (n / 2); i++) { cache.Put(new CloneableInteger(i), dummy); } // access every 4th item in cache for (int i = 0; i < n; i += 4) { Assert.IsNotNull(cache.Get(new CloneableInteger(i))); } // add 3/4n elements to cache, the ones that weren't // touched in the previous loops should now be thrown away for (int i = n; i < n + (n * 3 / 4); i++) { cache.Put(new CloneableInteger(i), dummy); } // access every 4th item in cache for (int i = 0; i < n; i += 4) { Assert.IsNotNull(cache.Get(new CloneableInteger(i))); } }
public override void Run() { try { long count = 0; long miss = 0; long hit = 0; int limit = Objs.Length; while (true) { CloneableObject obj = Objs[(int)((count / 2) % limit)]; object v = c.Get(obj); if (v == null) { c.Put(new CloneableObject(obj), obj); miss++; } else { Assert.True(obj == v); hit++; } if ((++count % 10000) == 0) { if (DateTime.Now.CompareTo(EndTime) > 0) { break; } } } OuterInstance.AddResults(miss, hit); } catch (Exception t) { Failed = true; throw new Exception(t.Message, t); } }