performance optimization in C#
2008-12-10 22:24
561 查看
1. Used always sealed classes when the class haven't any derived classes.
Some additional infos from this point:
The sealed modifier is primarily used to prevent unintended derivation,
but it also enables certain run-time optimizations. In particular, because a sealed class is
known to never have any derived classes, it is possible to transform virtual function member
invocations on sealed class instances into non-virtual invocations.
sealed类可以提高性能
2. Do not loop in a foreach loop over DataRows use the Select() method of the DataTable.
this code costs tooooo much:
foreach(DataRow currentDataRow in currentDataTable.Rows)
{
newDataTable.ImportRow(currentDataRow);
}
this code runs over 300 % faster (depends on rows count):
DataRow[] allRows = currentDataTable.Select();
foreach (DataRow currentDataRow in allRows)
{
newDataTable.ImportRow(currentDataRow);
}
Some additional infos from this point:
The sealed modifier is primarily used to prevent unintended derivation,
but it also enables certain run-time optimizations. In particular, because a sealed class is
known to never have any derived classes, it is possible to transform virtual function member
invocations on sealed class instances into non-virtual invocations.
sealed类可以提高性能
2. Do not loop in a foreach loop over DataRows use the Select() method of the DataTable.
this code costs tooooo much:
foreach(DataRow currentDataRow in currentDataTable.Rows)
{
newDataTable.ImportRow(currentDataRow);
}
this code runs over 300 % faster (depends on rows count):
DataRow[] allRows = currentDataTable.Select();
foreach (DataRow currentDataRow in allRows)
{
newDataTable.ImportRow(currentDataRow);
}
相关文章推荐
- [WorldWind学习]18.High-Performance Timer in C#
- High-Performance Timer in C#
- Optimizing C# Refactoring Performance with Web Projects in VS 2005
- How to write the fast code/ high performance in C#
- Does the “LINQ to Objects” provider have built-in performance optimization?
- C# in Depth
- C# Chat曲线图,在发布之后出现错误 Invalid temp directory in chart handler configuration c:\TempImageFiles\
- Microsoft Audio Compression Manager (ACM) in C#.NET
- Permissions in C#
- [转自微软网站]Making a Phone Call in C#
- C#中的BeforeFieldInit
- Working with Files in C#
- Timer Objects in Windows Services with C#.NET
- CPS (Continuation-Passing Style) in C#
- javaperformanceoptimization
- Writing Efficient String Functions in C#
- unhandled exception in c#(转)
- Creating Collection Classes in C#
- C# Inconsistant accessibility:property type "XXX" is less accessible than property "XXX"
- 【CRL in c#】常量与字段