Start by doing things right from the start. Think in term of performance right from the start and not till optimization stage.
Some links for those exploring further:
http://dotnet.sys-con.com/node/46342
Written in 2004, so some of the tools it mentioned are dated ones.
Avoiding Overuse of Property Getters and Setters
Most people don't realize that property getters and setters are similar to methods when it comes to overhead; it's mainly syntax that differentiates them. A non-virtual property getter or setter that contains no instructions other than the field access will be inlined by the compiler, but in many other cases, this isn't possible. You should carefully consider your use of properties; from inside a class, access fields directly (if possible) …
http://www.csharphelp.com/2010/02/c-best-practices-to-write-high-performance-code/
Read Values From Objects Only Once
Reading values from objects is not as fast as assessing the value of a simple variable. For example, a loop through an array’s contents should not access the array’s Length property on each iteration of the loop, instead copy the Length property to an Integer and then access this value on each iteration.
This applies to any classes you create as well, read all properties into a simple string or integer type if possible and then access that type multiple times.For Instead of ForEach
ForEach can simplify the code in a For loop but it is a heavy object and is slower than a loop written using For.
0 comments:
Post a Comment