// A prototype implementation of the subsystems mechanism for provably safe exception handling -- performance tests // Bart Jacobs and Frank Piessens , 2008 // http://www.cs.kuleuven.be/~bartj/subsystems // Last update: 2008-03-20 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Subsystems; using System.Runtime.CompilerServices; namespace PerfTests { class Program { static void Main(string[] args) { Test3(); Test1(); Test2(); } private static void Test3() { int n = 1000000; Console.WriteLine("Running ExecuteCodeWithGuaranteedCleanup({},{}) " + n + " times."); int ticks0 = Environment.TickCount; for (int i = 0; i < n; i++) { RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup((userData) => { }, (userData, exceptionThrown) => { }, null); } int ticks = Environment.TickCount - ticks0; Console.WriteLine("ExecuteCodeWithGuaranteedCleanup({},{}): " + 1.0 * ticks * 1000000 / n + " nanos"); } static void Test1() { int n = 100000; Console.WriteLine("Running TryCatch({},{}) " + n + " times."); int ticks0 = Environment.TickCount; Subsystem s0 = new Subsystem(); s0.Enter(() => { for (int i = 0; i < n; i++) { Subsystem.TryCatch(() => { }, (e) => { }); } }); int ticks = Environment.TickCount - ticks0; Console.WriteLine("TryCatch({},{}): " + 1.0 * ticks * 1000000 / n + " nanos"); } static void Test2() { int n = 100000; Console.WriteLine("Running TryCatch({Enter({})},{}) " + n + " times."); int ticks0 = Environment.TickCount; Subsystem s0 = new Subsystem(); s0.Enter(() => { for (int i = 0; i < n; i++) { Subsystem.TryCatch(() => { s0.Enter(() => { }); }, (e) => { }); } }); int ticks = Environment.TickCount - ticks0; Console.WriteLine("TryCatch({Enter({})},{}): " + 1.0 * ticks * 1000000 / n + " nanos"); } } }