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);
}
本文介绍两种提升软件性能的方法:一是使用sealed类以防止派生并利用运行时优化;二是改进数据处理方式,通过使用DataTable的Select方法替代foreach循环来显著提高处理速度。
5208

被折叠的 条评论
为什么被折叠?



