Question about string interning performance

I am curious. A script is a web application / website, for example. 100 simultaneous connections and many (20?) Page loads per second.

If the application requires a formatted string server

string.Format("Hello, {0}", username);

Will there be an interval between "Hello, {0}"? Or he will only be interned with

string hello = "Hello, {0}";
string.Format(hello, username);

What about internment will give better performance: higher or,

StringBuilder builder = new StringBuilder()
builder.Append("Hello, ");
builder.Append(username);

or even

string hello = "Hello, {0}";
StringBuilder builder = new StringBuilder()
builder.Append("Hello, ");
builder.Append(username);

So, my main questions: 1) Will the string string.Format be interpolated 2) Is it worth it to set the variable name for the string constructor for a quick search, or 3) Is the viewing itself quite difficult (if No. 1 is above, no)

I understand that this is likely to lead to small gains, but, as I said, I'm curious.

+3
4

String.Format StringBuilder , . , , #, .

, - . - , , , . , .

+3

Quick answer: iterate over 100k and find out.

0
source

You can't beat

return "Hello, " + username;

if your script is really that simple.

0
source

Source: https://habr.com/ru/post/1751448/


All Articles