StringBuilder vs XmlTextWriter

前端 未结 4 1253
独厮守ぢ
独厮守ぢ 2020-12-31 15:57

I am trying to squeeze as much performance as i can from a custom HttpHandler that serves Xml content.

I\' m wondering which is better for performance. Using the Xm

4条回答
  •  萌比男神i
    2020-12-31 16:13

    I agree that XmlWriter is better for code maintainability, but if we are talking about performance optimization, you should avoid both XmlWriter and StringBuilder.AppendFormat, because using a formatter ruins performance.

    changing

    sb.AppendFormat("{0}", content);
    

    to

    sb.Append("").Append(content).Append("");
    

    makes the StringBuilder version 2.5 times faster then the other from Robert's answer.

提交回复
热议问题