private static void FactoryCreatAnimalLoop() { AnimalFactory animal = null; Console.WriteLine("\n---------------------------"); Console.WriteLine("FactoryCreatAnimalLoop 100K"); Console.WriteLine("\n---------------------------"); var factory = new ZooFactory(); var zooFactoryA = new ZooFactoryA(factory); var stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < 100000; i++) { animal = zooFactoryA.CreateAnimal("Cat"); } stopWatch.Stop(); var ts = stopWatch.Elapsed; Console.WriteLine($"Time needed to create Instance call: Seconds {ts.Seconds:00} Milliseconds: {ts.Milliseconds:00} Ticks:{ts.Ticks}"); Console.WriteLine(animal.ToString()); }
public Animal CreateAnimal(string type) { Animal animal = ZooFactory.CreateAnimal(type); return(animal); }