c# - How expensive is data templating? -


i have performance problems , trying dig reasons.

so far not sure problem , next assumption it's data templating. question: how expensive using data-templating?

lets see how expensive single data template. below mcve.

xaml:

<window.resources>     <datatemplate datatype="{x:type local:item}">         <stackpanel>             <textblock text="{binding property1}" />              ... add here more things see difference         </stackpanel>     </datatemplate> </window.resources> <contentcontrol content="{binding content}" /> 

cs:

class item : inotifypropertychanged {     public event propertychangedeventhandler propertychanged;      public string property1 { get; set; } = "1";     public string property2 { get; set; } = "2";     public string property3 { get; set; } = "3";     public string property4 { get; set; } = "4";     public string property5 { get; set; } = "5"; }  class viewmodel : inotifypropertychanged {     public event propertychangedeventhandler propertychanged;      public object content { get; set; } = new item(); }  public partial class mainwindow : window {     public mainwindow()     {         initializecomponent();         datacontext = new viewmodel();     } } 

and here results (measured vs profiler - application timeline in ms):

test nb ni  presenter    items                         bindings    1  1   2.42 (0.57)                                1.8 b    5  5   3.37 (1.15)                                1.8, 0.07, 0.1, 0.05, 0.08 c    5  10  3.63 (1.27)  0.06, 0.07, 0.08, 0.04, 0.04  1.7, 0.08, 0.05, 0.06, 0.05 d    0  1   3.38 (0.6)   2.7 

explanation:

  • nb - number of bindings;
  • ni - number of items (elements);
  • presenter - time of contentpresenter (total/self);
  • items - items without binding times (when applicable);
  • bidings - items bindings times (when applicable).
  • a - initial test, 1 textblock single text binding.
  • b - added 4 more textblock bind text other properties.
  • c - added 5 more textblock static text="123".
  • d - removed except 1 textblock static text.

from can see, template takes 0.5 ms. there big cost creating first item (why???).

to honest not sure in correctness of method measure performance. therefore question. should avoid data-templating , start using old way of populating controls manually gain performance or what?


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -