[asp.net] Added code to handle local resources copying in the test suite
[mono.git] / mcs / class / Mono.C5 / UserGuideExamples / Try.cs
index 6617ffad48deb73844dab724aaada079b695d6d2..b1d89394dac9ac9e841802b05adfafc41dd8192e 100644 (file)
@@ -1,64 +1,79 @@
-/*\r
- Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft\r
- Permission is hereby granted, free of charge, to any person obtaining a copy\r
- of this software and associated documentation files (the "Software"), to deal\r
- in the Software without restriction, including without limitation the rights\r
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
- copies of the Software, and to permit persons to whom the Software is\r
- furnished to do so, subject to the following conditions:\r
\r
- The above copyright notice and this permission notice shall be included in\r
- all copies or substantial portions of the Software.\r
\r
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- SOFTWARE.\r
-*/\r
-\r
-// C5 example: various tests 2005-01-01\r
-\r
-// Compile with \r
-//   csc /r:C5.dll Try.cs \r
-\r
-using System;\r
-using System.Text;\r
-using C5;\r
-using SCG = System.Collections.Generic;\r
-\r
-namespace Try\r
-{\r
-  class MyTest\r
-  {\r
-    public static void Main()\r
-    {\r
-      IList<bool> list = new ArrayList<bool>();\r
-      list.AddAll(new bool[] { false, false, true, true, false });\r
-      list.CollectionCleared \r
-       += delegate(Object coll, ClearedEventArgs args) {\r
-         ClearedRangeEventArgs crargs = args as ClearedRangeEventArgs;\r
-         if (crargs != null) {\r
-           Console.WriteLine("Cleared {0} to {1}", \r
-                             crargs.Start, crargs.Start+crargs.Count-1);\r
-         } else {\r
-           Console.WriteLine("Cleared {0} items", args.Count);\r
-         }\r
-       };\r
-      list.RemoveInterval(2, 2);\r
-      HashSet<int> hash = new HashSet<int>();\r
-      hash.ItemsRemoved \r
-       += delegate {\r
-         Console.WriteLine("Item was removed");\r
-       };\r
-      hash.ItemsAdded \r
-       += delegate {\r
-         Console.WriteLine("Item was added");\r
-       };\r
-      hash.UpdateOrAdd(2);\r
-      hash.UpdateOrAdd(2);\r
-    }\r
-  }\r
-}\r
+/*
+ Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+*/
+
+// C5 example: various tests 2005 and later
+
+// Compile with 
+//   csc /r:C5.dll Try.cs 
+
+using System;
+using System.Text;
+using C5;
+using SCG = System.Collections.Generic;
+
+namespace Try
+{
+  class MyTest
+  {
+    public static void Main(String[] args)
+    {
+      SCG.IEqualityComparer<int> natural = EquatableEqualityComparer<int>.Default;
+      SCG.IEqualityComparer<int> c5comp = EqualityComparer<int>.Default;
+      int count = int.Parse(args[0]);
+      {
+        bool res = false;
+        Timer t = new Timer();
+        for (int i = count; i > 0; i--)
+        {
+          res = natural.Equals(4, 5);
+        }
+        Console.WriteLine("Time = {0} ns/comparison\n", t.Check() * 1E9 / count);
+      }
+      {
+        bool res = false;
+        Timer t = new Timer();
+        for (int i = count; i > 0; i--)
+        {
+          res = c5comp.Equals(4, 5);
+        }
+        Console.WriteLine("Time = {0} ns/comparison\n", t.Check() * 1E9 / count);
+      }
+    }
+  }
+
+  // Crude timing utility ----------------------------------------
+
+  public class Timer
+  {
+    private DateTime start;
+
+    public Timer()
+    {
+      start = DateTime.Now;
+    }
+
+    public double Check()
+    {
+      TimeSpan dur = DateTime.Now - start;
+      return dur.TotalSeconds;
+    }
+  }
+}