public static MyRect GetRect(Color color) { MyRect rect = rectsByColor.FirstOrDefault(c => c.Key == color).Value; if (rect == null) { rect = new MyRect(color); rectsByColor.Add(color, rect); } return(rect); }
private void StartDrawing_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); long startTime = DateTime.Now.Millisecond; for (int i = 0; i < 100000; i++) { MyRect rect = RectFactory.GetRect(GetRandColor()); rect.Draw(g, getRandX(), getRandY(), getRandX(), getRandY()); } long endTime = DateTime.Now.Millisecond; Console.WriteLine("That took " + (endTime - startTime)); }