You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by bo...@apache.org on 2015/03/31 15:25:11 UTC

svn commit: r1670333 - in /logging/log4net/trunk/src/playground: ./ AbsoluteTimeDateFormatterTiming.cs

Author: bodewig
Date: Tue Mar 31 13:25:10 2015
New Revision: 1670333

URL: http://svn.apache.org/r1670333
Log:
silly little timimg helper for LOG4NET-376

Added:
    logging/log4net/trunk/src/playground/
    logging/log4net/trunk/src/playground/AbsoluteTimeDateFormatterTiming.cs   (with props)

Added: logging/log4net/trunk/src/playground/AbsoluteTimeDateFormatterTiming.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/playground/AbsoluteTimeDateFormatterTiming.cs?rev=1670333&view=auto
==============================================================================
--- logging/log4net/trunk/src/playground/AbsoluteTimeDateFormatterTiming.cs (added)
+++ logging/log4net/trunk/src/playground/AbsoluteTimeDateFormatterTiming.cs Tue Mar 31 13:25:10 2015
@@ -0,0 +1,64 @@
+#region Apache License
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more 
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership. 
+// The ASF licenses this file to you under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with 
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using System;
+using System.IO;
+using System.Threading;
+using log4net.DateFormatter;
+
+namespace log4net.playground {
+
+    // dmcs -m:log4net.playground.AbsoluteTimeDateFormatterTiming -r:build/bin/log4net-1.3/mono/4.0/debug/log4net-1.3.dll src/playground/AbsoluteTimeDateFormatterTiming.cs
+    public class AbsoluteTimeDateFormatterTiming {
+
+        private static long TICKS = 0;
+
+        private static readonly Random RND = new Random(Environment.TickCount);
+        private static readonly AbsoluteTimeDateFormatter F = new AbsoluteTimeDateFormatter();
+        
+        public static void Main(string[] args) {
+
+            Thread[] threads = new Thread[20];
+            for (int i = 0; i < threads.Length; i++) {
+                threads[i] = new Thread(SingleThread);
+                threads[i].Start();
+            }
+            for (int i = 0; i < threads.Length; i++) {
+                threads[i].Join();
+            }
+
+            Console.Error.WriteLine("used {0} ticks", TICKS);
+        }
+
+        private static void SingleThread() {
+            StringWriter sw = new StringWriter();
+            for (int i = 0; i < 1000; i++) {
+                Thread.Sleep(RND.Next(15));
+                int before = Environment.TickCount;
+                for (int j = 0; j < 1000; j++) {
+                    F.FormatDate(DateTime.Now, sw);
+                }
+                int after = Environment.TickCount;
+                Interlocked.Add(ref TICKS, after - before);
+            }
+        }
+
+    }
+
+}
\ No newline at end of file

Propchange: logging/log4net/trunk/src/playground/AbsoluteTimeDateFormatterTiming.cs
------------------------------------------------------------------------------
    svn:eol-style = native