private static void PerformanceTest2() { var tracer = new StopwatchTracer(); Binder.SetTracer(tracer); var action = new BindingAction <string> { Action = TestExecute }; var ctx = "abc"; var binding = new Binding1 { Action = () => action.Action(ctx) }; IBinding binding2 = new Binding2 <string> { Action = action, Context = ctx }; var action3 = new BindingAction3 { Action = x => TestExecute((string)x) }; var binding3 = new Binding3 { Action = action3, Context = ctx }; var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 100000000; ++i) { //binding.Action(); //binding2.Execute(); binding3.Execute(); } sw.Stop(); // expected result: 400ms on average workstation Console.WriteLine($"Total: {sw.ElapsedMilliseconds}ms"); Console.WriteLine($"Bindings: {tracer.Elapsed.TotalMilliseconds}ms"); Console.ReadLine(); }
/// <summary> /// This basic implementation just sets a binding on the targeted /// <see cref="DependencyObject" /> and returns the appropriate /// <see cref="BindingExpressionBase" /> instance.<br /> /// All this work is delegated to the decorated <see cref="Binding" /> /// instance. /// </summary> /// <returns> /// The object value to set on the property where the extension is applied. /// In case of a valid binding expression, this is a <see cref="BindingExpressionBase" /> /// instance. /// </returns> /// <param name="provider"> /// Object that can provide services for the markup /// extension. /// </param> public override object ProvideValue(IServiceProvider provider) { //create a binding and associate it with the target return(Binding1.ProvideValue(provider)); }