Пример #1
0
        public void BitPseudoLru_cache_half(int x)
        {
            var pm = new PerformaceMonitor(start: true);

            var cache = new BitPseudoLruMap <string, string>(valueIsKey.WithThunderingHerdProtection(), keys.Length / 2);

            ReadMixKeys(keys, cache);

            pm.Stop();
            Console.WriteLine(pm.Report(keys.Length, cache.Count) + $", {valueIsKey.HitCount} hits to underlying data source");
            GC.KeepAlive(cache);
            GC.KeepAlive(keys);
        }
Пример #2
0
        public void BitPseudoLru_cache_half(int items)
        {
            string[] keys = CreateKeyStrings(items);
            var      pm   = new PerformaceMonitor(start: true);

            var cache = new BitPseudoLruMap <string, string>(valueIsKey, items / 2);

            ReadMixKeys(keys, cache);

            pm.Stop();
            Console.WriteLine(pm.Report(items, cache.Count));
            GC.KeepAlive(cache);
            GC.KeepAlive(keys);
        }
Пример #3
0
        public void BitPseudoLru_cache_memory_overhead(int items)
        {
            var sw = new Stopwatch();

            string[] keys     = CreateKeyStrings(items);
            var      starting = GC.GetTotalMemory(true);

            sw.Start();
            var cache = new BitPseudoLruMap <string, string>(valueIsKey, items);

            foreach (var key in keys)
            {
                Assert.AreEqual(key, cache[key]);
            }
            sw.Stop();
            var allocated = GC.GetTotalMemory(false) - starting;
            var held      = GC.GetTotalMemory(true) - starting;

            Console.WriteLine($"Took {sw.ElapsedMilliseconds:N0} ms, {items} added to cache, {cache.Count} item in the cache, allocated {allocated:N0} bytes, holding {held:N0} bytes, overhead per item {held / (double)items:N2} bytes");
            GC.KeepAlive(cache);
            GC.KeepAlive(keys);
        }