public LessThanConstraints(ExpressionManagerWithEncoder <Variable, Expression> expManager) { Contract.Requires(expManager != null); this.expManager = expManager; cache = new FIFOCache <Pair <Expression, Expression>, Cache_Entry <Expression> >(16); }
void Test(int t, int n, ISchedule schedule, string scheduleName) { var graph = new GraphGenerator(1000, 600); var Listk = new List <int> { 10, 9, 8, 7, 6, 5 }; Listk = Listk.Select(x => n / x).Distinct().ToList(); var fifol = new List <double>(); var fwfl = new List <double>(); var lrul = new List <double>(); var lful = new List <double>(); var randl = new List <double>(); var rmal = new List <double>(); Listk.ForEach(k => { int fifoc, fwfc, lruc, lfuc, randc, rmac; fifoc = fwfc = lruc = lfuc = randc = rmac = 0; for (int j = 0; j < 100; j++) { var fifo = new FIFOCache(k); var fwf = new FWFCachecs(k); var lru = new LRUCache(k); var lfu = new LFUCache(k); var rand = new RandCache(k); var rma = new RMACache(k); for (int i = 0; i < t; i++) { var x = schedule.GetNextNumber(); fifoc += fifo.GetValue(x); fwfc += fwf.GetValue(x); lruc += lru.GetValue(x); lfuc += lfu.GetValue(x); randc += rand.GetValue(x); rmac += rma.GetValue(x); } } fifol.Add(fifoc / 100); fwfl.Add(fwfc / 100); lrul.Add(lruc / 100); lful.Add(lfuc / 100); randl.Add(randc / 100); rmal.Add(rmac / 100); }); var kk = Listk.Select(x => (double)x).ToList(); graph.AddSeries($"{scheduleName}_FIFO_", System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line, kk, fifol, Color.Red); graph.AddSeries($"{scheduleName}_FWF_", System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line, kk, fwfl, Color.Blue); graph.AddSeries($"{scheduleName}_LRU_", System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line, kk, lrul, Color.Black); graph.AddSeries($"{scheduleName}_LFU_", System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line, kk, lful, Color.Yellow); graph.AddSeries($"{scheduleName}_RAND_", System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line, kk, randl, Color.Green); graph.AddSeries($"{scheduleName}_RMA_", System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line, kk, rmal, Color.MediumPurple); graph.SaveGraph($"{scheduleName}_{n}_3"); }
public static void TestReplace() { FIFOCache <int, int> cache = new FIFOCache <int, int>(2); cache[1] = 1; cache[2] = 2; Assert.AreEqual(cache.Count, 2); cache[3] = 3; Assert.IsFalse(cache.ContainsKey(1)); Assert.IsTrue(cache.ContainsKey(3)); }
static void FIFOCacheTest() { try { bool runForever = true; byte[] data = InitByteArray(_DataLength, 0x00); byte[] keyData; Persistence persistence = new Persistence("./cache"); FIFOCache <string, byte[]> cache = new FIFOCache <string, byte[]>(_Capacity, _EvictCount, persistence); Thread.Sleep(250); while (runForever) { Console.Write("Command > "); string userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { continue; } switch (userInput.ToLower()) { case "?": MenuFIFO(); break; case "get": Console.Write("Key > "); string getKey = Console.ReadLine(); if (String.IsNullOrEmpty(getKey)) { break; } if (cache.TryGet(getKey, out keyData)) { Console.WriteLine("Cache hit"); } else { Console.WriteLine("Cache miss"); } break; case "all": Dictionary <string, byte[]> dump = cache.All(); if (dump != null && dump.Count > 0) { foreach (KeyValuePair <string, byte[]> entry in dump) { Console.WriteLine(entry.Key); } Console.WriteLine("Count: " + dump.Count + " entries"); } else { Console.WriteLine("Empty"); } break; case "load": DateTime startTime = DateTime.Now; for (int i = 0; i < _LoadCount; i++) { string loadKey = Guid.NewGuid().ToString(); Console.Write("Adding entry " + i + " of " + _LoadCount + " \r"); cache.AddReplace(loadKey, data); } Console.WriteLine( "Loaded " + _LoadCount + " records in " + TotalTimeFrom(startTime) + ": " + DecimalToString(TotalMsFrom(startTime) / _LoadCount) + "ms per entry"); break; case "oldest": Console.WriteLine("Oldest key: " + cache.Oldest()); break; case "newest": Console.WriteLine("Newest key: " + cache.Newest()); break; case "count": Console.WriteLine("Cache count: " + cache.Count()); break; case "clear": cache.Clear(); Console.WriteLine("Cache cleared"); break; case "q": case "quit": runForever = false; break; default: continue; } } Console.WriteLine("Goodbye!"); return; } catch (Exception e) { PrintException(e); } finally { Console.WriteLine(""); Console.Write("Press ENTER to exit."); Console.ReadLine(); } }
static void FIFOCacheTest() { try { bool runForever = true; int capacity = 2048; int evictCount = 512; int loadCount = 256; bool cacheDebug = true; int dataLen = 4096; byte[] data = InitByteArray(dataLen, 0x00); byte[] keyData; FIFOCache <string, byte[]> cache = new FIFOCache <string, byte[]>(capacity, evictCount, cacheDebug); Thread.Sleep(250); while (runForever) { Console.WriteLine("-------------------------------------------------------------------------------"); Console.WriteLine("Available commands (FIFO Cache Test):"); Console.WriteLine(" get Get entry by key"); Console.WriteLine(" load Load " + loadCount + " new records"); Console.WriteLine(" oldest Get the oldest entry"); Console.WriteLine(" newest Get the newest entry"); Console.WriteLine(" count Get the count of cached entries"); Console.WriteLine(" clear Clear the cache"); Console.WriteLine(" quit Exit the application"); Console.WriteLine(" debug Flip the cache debug flag (currently " + cache.Debug + ")"); Console.WriteLine(""); Console.Write("Command > "); string userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { continue; } switch (userInput.ToLower()) { case "get": Console.Write("Key > "); string getKey = Console.ReadLine(); if (String.IsNullOrEmpty(getKey)) { break; } if (cache.TryGet(getKey, out keyData)) { Console.WriteLine("Cache hit"); } else { Console.WriteLine("Cache miss"); } break; case "load": DateTime startTime = DateTime.Now; for (int i = 0; i < loadCount; i++) { string loadKey = Guid.NewGuid().ToString(); Console.Write("Adding entry " + i + " of " + loadCount + " \r"); cache.AddReplace(loadKey, data); } Console.WriteLine( "Loaded " + loadCount + " records in " + TotalTimeFrom(startTime) + ": " + DecimalToString(TotalMsFrom(startTime) / loadCount) + "ms per entry"); break; case "oldest": Console.WriteLine("Oldest key: " + cache.Oldest()); break; case "newest": Console.WriteLine("Newest key: " + cache.Newest()); break; case "count": Console.WriteLine("Cache count: " + cache.Count()); break; case "clear": cache.Clear(); Console.WriteLine("Cache cleared"); break; case "q": case "quit": runForever = false; break; case "debug": cache.Debug = !cache.Debug; break; default: continue; } } Console.WriteLine("Goodbye!"); return; } catch (Exception e) { PrintException(e); } finally { Console.WriteLine(""); Console.Write("Press ENTER to exit."); Console.ReadLine(); } }