Connection string (directly + with stringbuilder)

Source: Internet
Author: User

private static readonly string STR = "0123456789";/************************************
The string. Concat method is used for common connection operations. A new string is generated each time.
*************************************/private static string NormalConcat(int count){    var result = "";    for (int i = 0; i < count; i++) result += STR;    return result;}/*****************************
Almost all the time is spent on the append operation (this is nonsense ). In the append method, the appendinplace and getnewstring Methods Both occupy a large proportion.
From the previous code analysis, we know that the appendinplace method copies the new string to the back of the original character sequence (that is, the "Container,
The function of getnewstring is to create a new, doubling capacity string (container)-the main consumption of it is on the getstringforstringbuilder method.
******************************/private static string StringBuilder(int count){    var builder = new StringBuilder();    for (int i = 0; i < count; i++) builder.Append(STR);    return builder.ToString();}

More discussion: http://blog.zhaojie.me/2009/11/string-concat-perf-1-benchmark.html

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.