static void Main(string[] args) { var eventListener = new MyEventListener(); var eventSource = new MyEventSource(); eventSource.AnEvent += eventListener.Receive; var eventArgs = new EventArgs(); eventSource.InvokeAnEvent(eventArgs); const int Count = 3000000; var then = DateTime.Now; for (var iter = 0; iter < Count; ++iter) { eventSource.InvokeAnEvent(eventArgs); } var diff = DateTime.Now - then; Console.WriteLine( "{0} calls took {1:0.00} seconds (listener received {2} calls)", Count, diff.TotalSeconds, eventListener.Count ); Console.ReadKey(); }
static void Main(string[] args) { MyEventListener eventListener = new MyEventListener(); MyEventSource eventSource = new MyEventSource(); eventSource.AnEvent += eventListener.Receive; MyEventArgs eventArgs = new MyEventArgs(); eventSource.InvokeAnEvent(eventArgs); const int count = 5000000; DateTime then = DateTime.Now; for (int iter = 0; iter < count; ++iter) { eventSource.InvokeAnEvent(eventArgs); } TimeSpan diff = DateTime.Now - then; Console.WriteLine( "{0} calls took {1:0.00} seconds (listener received {2} calls)", count, diff.TotalSeconds, eventListener.Count ); Console.ReadKey(); }