public void DelegatePerformanceTest()
        {
            int runs = 5000000;

            StopWatch sw;
            sw = new StopWatch();
            using(sw.Start("Time:{0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    PerformanceTestTarget(1, null, null);
                }
            }
            //            Trace.WriteLine( string.Format("Time:{0}", sw.Elapsed.TotalSeconds) );

            WriteHandler writeHandler = new WriteHandler(PerformanceTestTarget);
            using(sw.Start("Time:{0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    writeHandler(1, null, null);
                }
            }
            //            Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds));

            IWriteHandler writeHandler2 = this;
            using(sw.Start("Time:{0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    writeHandler2.PerformanceTestTarget(1, null, null);
                }
            }
            //            Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds));
        }
示例#2
0
        public void DelegatePerformanceTest()
        {
            int runs = 5000000;

            StopWatch sw;

            sw = new StopWatch();
            using (sw.Start("Time:{0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    PerformanceTestTarget(1, null, null);
                }
            }
//            Trace.WriteLine( string.Format("Time:{0}", sw.Elapsed.TotalSeconds) );

            WriteHandler writeHandler = new WriteHandler(PerformanceTestTarget);

            using (sw.Start("Time:{0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    writeHandler(1, null, null);
                }
            }
//            Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds));

            IWriteHandler writeHandler2 = this;

            using (sw.Start("Time:{0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    writeHandler2.PerformanceTestTarget(1, null, null);
                }
            }
//            Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds));
        }
示例#3
0
        public void DiagnosticsTracePerformanceTest()
        {
            MyTestObjectUnderTrace myObj = new MyTestObjectUnderTrace();
            int                 runs     = 100000000;
            StopWatch           sw;
            MyTestTraceListener listener;

            // use NoOp logging
            LogManager.Adapter = new NoOpLoggerFactoryAdapter();
            ILog log = LogManager.GetLogger(this.GetType());

            sw = new StopWatch();
            using (sw.Start("Time:{0} - log.InfoFormat + NoOpLogger"))
            {
                for (int i = 0; i < runs; i++)
                {
                    log.Info(m => m("some logger info {0}", (object)myObj));
                }
            }

            // Use unconfigured TraceSource
            TraceSource traceSource = new TraceSource("bla");

            sw = new StopWatch();
            using (sw.Start("Time:{0} - traceSource.TraceEvent + unconfigured TraceSource"))
            {
                for (int i = 0; i < runs; i++)
                {
                    if (traceSource.Switch.ShouldTrace(TraceEventType.Information))
                    {
                        traceSource.TraceEvent(TraceEventType.Information, -1, "some tracesource info {0}", (object)myObj);
                    }
                }
            }

            // use Common.Logging
            MyTestLoggerFactoryAdapter adapter = new MyTestLoggerFactoryAdapter(null);

            adapter.ShowLogName  = true;
            adapter.ShowDateTime = true;
            adapter.Level        = LogLevel.Warn;
            LogManager.Adapter   = adapter;
            log = LogManager.GetLogger(this.GetType());

            sw = new StopWatch();
            using (sw.Start("Time:{0} - log.InfoFormat"))
            {
                for (int i = 0; i < runs; i++)
                {
                    log.Info(m => m("some logger info {0}", (object)myObj));
                }
            }
            Assert.AreEqual(0, adapter.Messages.Count);

            // Use configured TraceSource
            traceSource = new TraceSource("DiagnosticsTracePerformanceTest");
            listener    = (MyTestTraceListener)traceSource.Listeners[0];
            sw          = new StopWatch();
            using (sw.Start("Time:{0} - traceSource.TraceEvent"))
            {
                for (int i = 0; i < runs; i++)
                {
                    if (traceSource.Switch.ShouldTrace(TraceEventType.Information))
                    {
                        traceSource.TraceEvent(TraceEventType.Information, -1, "some tracesource info {0}", (object)myObj);
                    }
                }
            }
            Assert.AreEqual(0, listener.Messages.Count);
        }
示例#4
0
 public Stopper(StopWatch owner, string format)
 {
     _owner = owner;
     _format = format;
 }
        public void DiagnosticsTracePerformanceTest()
        {
            MyTestObjectUnderTrace myObj = new MyTestObjectUnderTrace();
            int runs = 100000000;
            StopWatch sw;
            MyTestTraceListener listener;

            // use NoOp logging
            LogManager.Adapter = new NoOpLoggerFactoryAdapter();
            ILog log = LogManager.GetLogger(this.GetType());

            sw = new StopWatch();
            using (sw.Start("Time:{0} - log.InfoFormat + NoOpLogger"))
            {
                for (int i = 0; i < runs; i++)
                {
                    log.Info( m=>m("some logger info {0}", (object)myObj) );
                }
            }

            // Use unconfigured TraceSource
            TraceSource traceSource = new TraceSource("bla");
            sw = new StopWatch();
            using (sw.Start("Time:{0} - traceSource.TraceEvent + unconfigured TraceSource"))
            {
                for (int i = 0; i < runs; i++)
                {
                    if (traceSource.Switch.ShouldTrace(TraceEventType.Information))
                    {
                        traceSource.TraceEvent(TraceEventType.Information, -1, "some tracesource info {0}", (object)myObj);
                    }
                }
            }

            // use Common.Logging
            MyTestLoggerFactoryAdapter adapter = new MyTestLoggerFactoryAdapter(null);
            adapter.ShowLogName = true;
            adapter.ShowDateTime = true;
            adapter.Level = LogLevel.Warn;
            LogManager.Adapter = adapter;
            log = LogManager.GetLogger(this.GetType());

            sw = new StopWatch();
            using (sw.Start("Time:{0} - log.InfoFormat"))
            {
                for (int i = 0; i < runs; i++)
                {
                    log.Info(m => m("some logger info {0}", (object)myObj));
                }
            }
            Assert.AreEqual(0, adapter.Messages.Count);

            // Use configured TraceSource
            traceSource = new TraceSource("DiagnosticsTracePerformanceTest");
            listener = (MyTestTraceListener) traceSource.Listeners[0];
            sw = new StopWatch();
            using (sw.Start("Time:{0} - traceSource.TraceEvent"))
            {
                for (int i = 0; i < runs; i++)
                {
                    if (traceSource.Switch.ShouldTrace(TraceEventType.Information))
                    {
                        traceSource.TraceEvent(TraceEventType.Information, -1, "some tracesource info {0}", (object)myObj);
                    }
                }
            }
            Assert.AreEqual(0, listener.Messages.Count);
        }
示例#6
0
 public Stopper(StopWatch owner, string format)
 {
     _owner  = owner;
     _format = format;
 }