Did you notice?
The String connection mode is 30 times times more than StringBuilder under test with only 1/100 data. Therefore, based on performance considerations, we do not recommend this approach. and StringBuilder compared to stringwriter slightly, the specific reasons will be analyzed in the next article. Of course, the tests are error-proof, but they are sufficient to illustrate the facts.
StringWriter and StringBuilder: Who is the strong
StringWriter is located within the System.IO namespace and inherits from TextWriter. Shown in the back-compilation result of the. Net Reflector, its interior is actually connected by StringBuilder. No wonder StringWriter will be slightly inferior, it turns out to be just an adaptation of StringBuilder (which can be called Adapter mode). Why is StringBuilder so efficient?
Did you notice?
In many places, StringWriter rather than StringBuilder, such as XmlTextWriter, are needed.
StringBuilder: why
On the research of System.Text.StringBuilder, there are many online, the main principle is to allocate the memory in an unmanaged way, guarantee the modification and expansion of the text, do not re-create a String object. The creation of a String object is a performance bottleneck. Its connection efficiency is far greater than string, but it is obvious that string programming is easier when a small amount of text is connected.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.