SlideShare ist ein Scribd-Unternehmen logo
1 von 13
C# String Concatenations
(Tested in Unity)
Sindharta Tanuwijaya
string str = “foo” + “bar”
Before I start
• These are the conclusions in the previous version of
the slides:
1. Use StringBuilder for performance critical code !
2. Never use plus concatenation !
3. For default usage, I personally recommend string.format
4. Prioritize code readability over performance
• Two were wrong, because of inaccurate tests.
– I’d like apologize to people who followed my previous
conclusions
Let’s Start
What I want to do
• Minimize memory usage
– Done wrongly, it can consume a lot of
unnecessary memory (yes, that’s right)
• Maximize speed
• Get the most bang for the buck
There are three methods, AFAIK
• The usual plus concatenation:
– “foo” + “bar”
• string.Format:
– string.Format(“{0} {1}”, foo.ToString(),bar.ToString());
• StringBuilder
– StringBuilder string_builder = new StringBuilder("");
string_builder.append(foo.ToString());
string_builder.append(bar.ToString());
• Some articles on the Internet suggest using StringBuilder,
and some suggest using string.Format, but I haven’t
found any that tries to compare them.
– So, I did it.
How I did the comparison
• Prepare 100 one-letter strings.
• Perform 1..100th one-letter string concatenations for each
method. For example:
– “1” + “2” => 2 one-letter string concatenations
– “1” + “2” + “3” => 3 one-letter string concatenations
• Measure only the concatenation time for each method,
which means initialization codes should not be included.
– Do the concatenation 1000 times, so that we have meaningful
numbers to measure.
• Output the results in a text file, visualize in Excel
• Full source code can be found here:
https://github.com/sindharta/unity-sandbox
– Open the StringTest scene.
Plus Concatenation
string.format
:
StringBuilder
Performance: Time
0
0.005
0.01
0.015
0.02
0.025
0.03
0.035
0.04
0.045
1
5
9
13
17
21
25
29
33
37
41
45
49
53
57
61
65
69
73
77
81
85
89
93
97
Concat
StringFormat
StringBuilder
• Plus Concatenation is fast at the beginning, but
becomes the slowest when concatenating more than
30 one-letter strings.
• StringBuilder is almost always the fastest.
Performance: Memory
0
200000
400000
600000
800000
1000000
1200000
1400000
1600000
1800000
1
5
9
13
17
21
25
29
33
37
41
45
49
53
57
61
65
69
73
77
81
85
89
93
97
Concat
StringFormat
StringBuilder
• Plus concatenation takes a little amount of memory at the beginning, but becomes
the most memory consuming method when concatenating more than 30 one-
letter strings.
• StringBuilder is almost always the one which uses the least amount of memory.
• (Should probably wrap the tests in a loop and then average the results, because of
the spikes. Anyway I think these results are illustrative enough).
Analyzing a little bit more
• string.Format always slower than StringBuilder. This is
understandable because string.Format uses StringBuilder internally.
• string.Format pays initial cost at the beginning for trying to parse the
string format, which pays off when concatenating a lot of strings.
• The results of concatenating strings which have more than one
letters would be a lot different than the results shown here.
– Longer strings would slow down plus concatenations because it needs to
allocate more memory to accommodate these longer strings. The impact
would be much less for the other two methods.
– For string.Format to be able to win against plus concatenation in the case of
just two string concatenations, I would guess that the strings must have
more than 450 letters (1+2+3+…30), but more accurate test is needed.
• Code readability in order:
1. Plus concatenation
2. string.Format
3. StringBuilder
Conclusion
• Use StringBuilder for performance critical code.
• Use plus concatenation for simple cases.
• In the case non-critical but a lot of string
concatenations, use string.Format.
• When confused, prioritize code readability over
performance by default.

Weitere ähnliche Inhalte

Was ist angesagt?

15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由
15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由
15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由
Yasuhiro Horiuchi
 

Was ist angesagt? (20)

StreamPaaSのご紹介
StreamPaaSのご紹介StreamPaaSのご紹介
StreamPaaSのご紹介
 
[DL輪読会]Understanding Measures of Uncertainty for Adversarial Example Detection
[DL輪読会]Understanding Measures of Uncertainty for Adversarial Example Detection[DL輪読会]Understanding Measures of Uncertainty for Adversarial Example Detection
[DL輪読会]Understanding Measures of Uncertainty for Adversarial Example Detection
 
Mac bookでwebサーバーを起動する方法
Mac bookでwebサーバーを起動する方法Mac bookでwebサーバーを起動する方法
Mac bookでwebサーバーを起動する方法
 
なぜソーシャルゲームはクラウドなのか? ~AWSの成功事例を紐解く~
なぜソーシャルゲームはクラウドなのか? ~AWSの成功事例を紐解く~なぜソーシャルゲームはクラウドなのか? ~AWSの成功事例を紐解く~
なぜソーシャルゲームはクラウドなのか? ~AWSの成功事例を紐解く~
 
スマートフォンゲームのチート事情
スマートフォンゲームのチート事情スマートフォンゲームのチート事情
スマートフォンゲームのチート事情
 
Dockerのディスクについて ~ファイルシステム・マウント方法など~
Dockerのディスクについて ~ファイルシステム・マウント方法など~Dockerのディスクについて ~ファイルシステム・マウント方法など~
Dockerのディスクについて ~ファイルシステム・マウント方法など~
 
Region推論アルゴリズムの実装と動向
Region推論アルゴリズムの実装と動向Region推論アルゴリズムの実装と動向
Region推論アルゴリズムの実装と動向
 
20201207 AWS Black Belt Online Seminar AWS re:Invent 2020 速報 Part1
20201207 AWS Black Belt Online Seminar AWS re:Invent 2020 速報 Part120201207 AWS Black Belt Online Seminar AWS re:Invent 2020 速報 Part1
20201207 AWS Black Belt Online Seminar AWS re:Invent 2020 速報 Part1
 
PHPの今とこれから2020
PHPの今とこれから2020PHPの今とこれから2020
PHPの今とこれから2020
 
React + Amplifyで アプリ開発
React + Amplifyで アプリ開発React + Amplifyで アプリ開発
React + Amplifyで アプリ開発
 
さくらのDockerコンテナホスティング-Arukasの解説とインフラを支える技術(July Tech Festa 2016 『IoTxAIxインフラ時代...
さくらのDockerコンテナホスティング-Arukasの解説とインフラを支える技術(July Tech Festa 2016 『IoTxAIxインフラ時代...さくらのDockerコンテナホスティング-Arukasの解説とインフラを支える技術(July Tech Festa 2016 『IoTxAIxインフラ時代...
さくらのDockerコンテナホスティング-Arukasの解説とインフラを支える技術(July Tech Festa 2016 『IoTxAIxインフラ時代...
 
15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由
15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由
15分でわかるAWSクラウドで オンプレ以上のセキュリティを実現できる理由
 
GoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホンGoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホン
 
Deep Dive: Amazon DynamoDB (db tech showcase 2016)
Deep Dive: Amazon DynamoDB (db tech showcase 2016) Deep Dive: Amazon DynamoDB (db tech showcase 2016)
Deep Dive: Amazon DynamoDB (db tech showcase 2016)
 
オトナのpandas勉強会(資料)
オトナのpandas勉強会(資料)オトナのpandas勉強会(資料)
オトナのpandas勉強会(資料)
 
AWSからのメール送信
AWSからのメール送信AWSからのメール送信
AWSからのメール送信
 
20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice
20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice
20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice
 
PHP Aula07 - conexão Com Banco de Dados
PHP Aula07 - conexão Com Banco de DadosPHP Aula07 - conexão Com Banco de Dados
PHP Aula07 - conexão Com Banco de Dados
 
DataGridを自前実装する話
DataGridを自前実装する話DataGridを自前実装する話
DataGridを自前実装する話
 
DynamoDBの初心者に伝えたい初めて触るときの勘所
DynamoDBの初心者に伝えたい初めて触るときの勘所DynamoDBの初心者に伝えたい初めて触るときの勘所
DynamoDBの初心者に伝えたい初めて触るときの勘所
 

Ähnlich wie C# string concatenations in unity (Updated 2014/7/11)

IntroPython-Week02-StringsIteration.pptx
IntroPython-Week02-StringsIteration.pptxIntroPython-Week02-StringsIteration.pptx
IntroPython-Week02-StringsIteration.pptx
chrisdy932
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
VinayakHospet1
 

Ähnlich wie C# string concatenations in unity (Updated 2014/7/11) (20)

IntroPython-Week02-StringsIteration.pptx
IntroPython-Week02-StringsIteration.pptxIntroPython-Week02-StringsIteration.pptx
IntroPython-Week02-StringsIteration.pptx
 
CNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code AuditingCNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code Auditing
 
Python VS GO
Python VS GOPython VS GO
Python VS GO
 
Introduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimizationIntroduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimization
 
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & SearchingHub 102 - Lesson 5 - Algorithm: Sorting & Searching
Hub 102 - Lesson 5 - Algorithm: Sorting & Searching
 
#GDC15 Code Clinic
#GDC15 Code Clinic#GDC15 Code Clinic
#GDC15 Code Clinic
 
Introduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimizationIntroduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimization
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performance
 
Ch 18: Source Code Auditing
Ch 18: Source Code AuditingCh 18: Source Code Auditing
Ch 18: Source Code Auditing
 
High-Performance Python
High-Performance PythonHigh-Performance Python
High-Performance Python
 
Introduction to Parallelization and performance optimization
Introduction to Parallelization and performance optimizationIntroduction to Parallelization and performance optimization
Introduction to Parallelization and performance optimization
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
Gpgpu intro
Gpgpu introGpgpu intro
Gpgpu intro
 
Brixton Library Technology Initiative Week0 Recap
Brixton Library Technology Initiative Week0 RecapBrixton Library Technology Initiative Week0 Recap
Brixton Library Technology Initiative Week0 Recap
 
Low Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling ExamplesLow Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling Examples
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
 

Kürzlich hochgeladen

Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...
Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...
Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...
Amil Baba Naveed Bangali
 
Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...
Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...
Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...
baharayali
 
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
makhmalhalaaay
 
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
baharayali
 
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
No -1 Astrologer ,Amil Baba In Australia | Uk | Usa | Canada | Pakistan
 
Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...
Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...
Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...
baharayali
 
Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

Amil baba in Lahore /Amil baba in Karachi /Amil baba in Pakistan
Amil baba in Lahore /Amil baba in Karachi /Amil baba in PakistanAmil baba in Lahore /Amil baba in Karachi /Amil baba in Pakistan
Amil baba in Lahore /Amil baba in Karachi /Amil baba in Pakistan
 
Codex Singularity: Search for the Prisca Sapientia
Codex Singularity: Search for the Prisca SapientiaCodex Singularity: Search for the Prisca Sapientia
Codex Singularity: Search for the Prisca Sapientia
 
From The Heart v8.pdf xxxxxxxxxxxxxxxxxxx
From The Heart v8.pdf xxxxxxxxxxxxxxxxxxxFrom The Heart v8.pdf xxxxxxxxxxxxxxxxxxx
From The Heart v8.pdf xxxxxxxxxxxxxxxxxxx
 
Human Design Gates Cheat Sheet | Kabastro.com
Human Design Gates Cheat Sheet | Kabastro.comHuman Design Gates Cheat Sheet | Kabastro.com
Human Design Gates Cheat Sheet | Kabastro.com
 
Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...
Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...
Top 10 Amil baba list Famous Amil baba In Pakistan Amil baba Kala jadu in Raw...
 
Balaghat Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Balaghat Escorts 🥰 8617370543 Call Girls Offer VIP Hot GirlsBalaghat Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Balaghat Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
 
Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...
Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...
Famous kala ilam, Bangali Amil baba in UAE and Kala jadu expert in Saudi Arab...
 
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
Professional Amil baba, Kala jadu specialist in Multan and Kala ilam speciali...
 
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
Popular Kala Jadu, Black magic specialist in Sialkot and Kala ilam specialist...
 
St. Louise de Marillac and Abandoned Children
St. Louise de Marillac and Abandoned ChildrenSt. Louise de Marillac and Abandoned Children
St. Louise de Marillac and Abandoned Children
 
Legends of the Light v2.pdf xxxxxxxxxxxxx
Legends of the Light v2.pdf xxxxxxxxxxxxxLegends of the Light v2.pdf xxxxxxxxxxxxx
Legends of the Light v2.pdf xxxxxxxxxxxxx
 
Emails, Facebook, WhatsApp and the Dhamma (English and Chinese).pdf
Emails, Facebook, WhatsApp and the Dhamma  (English and Chinese).pdfEmails, Facebook, WhatsApp and the Dhamma  (English and Chinese).pdf
Emails, Facebook, WhatsApp and the Dhamma (English and Chinese).pdf
 
The_Chronological_Life_of_Christ_Part_99_Words_and_Works
The_Chronological_Life_of_Christ_Part_99_Words_and_WorksThe_Chronological_Life_of_Christ_Part_99_Words_and_Works
The_Chronological_Life_of_Christ_Part_99_Words_and_Works
 
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
 
Jude: The Acts of the Apostate: High Handed Sins (vv.5-7).pptx
Jude: The Acts of the Apostate: High Handed Sins (vv.5-7).pptxJude: The Acts of the Apostate: High Handed Sins (vv.5-7).pptx
Jude: The Acts of the Apostate: High Handed Sins (vv.5-7).pptx
 
famous No 1 astrologer / Best No 1 Amil baba in UK, Australia, Germany, USA, ...
famous No 1 astrologer / Best No 1 Amil baba in UK, Australia, Germany, USA, ...famous No 1 astrologer / Best No 1 Amil baba in UK, Australia, Germany, USA, ...
famous No 1 astrologer / Best No 1 Amil baba in UK, Australia, Germany, USA, ...
 
Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...
Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...
Real Kala Jadu, Black magic specialist in Lahore and Kala ilam expert in kara...
 
Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Ponorogo ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Deerfoot Church of Christ Bulletin 5 12 24
Deerfoot Church of Christ Bulletin 5 12 24Deerfoot Church of Christ Bulletin 5 12 24
Deerfoot Church of Christ Bulletin 5 12 24
 
Pathankot Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Pathankot Escorts 🥰 8617370543 Call Girls Offer VIP Hot GirlsPathankot Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Pathankot Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
 

C# string concatenations in unity (Updated 2014/7/11)

  • 1. C# String Concatenations (Tested in Unity) Sindharta Tanuwijaya string str = “foo” + “bar”
  • 2. Before I start • These are the conclusions in the previous version of the slides: 1. Use StringBuilder for performance critical code ! 2. Never use plus concatenation ! 3. For default usage, I personally recommend string.format 4. Prioritize code readability over performance • Two were wrong, because of inaccurate tests. – I’d like apologize to people who followed my previous conclusions
  • 4. What I want to do • Minimize memory usage – Done wrongly, it can consume a lot of unnecessary memory (yes, that’s right) • Maximize speed • Get the most bang for the buck
  • 5. There are three methods, AFAIK • The usual plus concatenation: – “foo” + “bar” • string.Format: – string.Format(“{0} {1}”, foo.ToString(),bar.ToString()); • StringBuilder – StringBuilder string_builder = new StringBuilder(""); string_builder.append(foo.ToString()); string_builder.append(bar.ToString()); • Some articles on the Internet suggest using StringBuilder, and some suggest using string.Format, but I haven’t found any that tries to compare them. – So, I did it.
  • 6. How I did the comparison • Prepare 100 one-letter strings. • Perform 1..100th one-letter string concatenations for each method. For example: – “1” + “2” => 2 one-letter string concatenations – “1” + “2” + “3” => 3 one-letter string concatenations • Measure only the concatenation time for each method, which means initialization codes should not be included. – Do the concatenation 1000 times, so that we have meaningful numbers to measure. • Output the results in a text file, visualize in Excel • Full source code can be found here: https://github.com/sindharta/unity-sandbox – Open the StringTest scene.
  • 10. Performance: Time 0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 Concat StringFormat StringBuilder • Plus Concatenation is fast at the beginning, but becomes the slowest when concatenating more than 30 one-letter strings. • StringBuilder is almost always the fastest.
  • 11. Performance: Memory 0 200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 Concat StringFormat StringBuilder • Plus concatenation takes a little amount of memory at the beginning, but becomes the most memory consuming method when concatenating more than 30 one- letter strings. • StringBuilder is almost always the one which uses the least amount of memory. • (Should probably wrap the tests in a loop and then average the results, because of the spikes. Anyway I think these results are illustrative enough).
  • 12. Analyzing a little bit more • string.Format always slower than StringBuilder. This is understandable because string.Format uses StringBuilder internally. • string.Format pays initial cost at the beginning for trying to parse the string format, which pays off when concatenating a lot of strings. • The results of concatenating strings which have more than one letters would be a lot different than the results shown here. – Longer strings would slow down plus concatenations because it needs to allocate more memory to accommodate these longer strings. The impact would be much less for the other two methods. – For string.Format to be able to win against plus concatenation in the case of just two string concatenations, I would guess that the strings must have more than 450 letters (1+2+3+…30), but more accurate test is needed. • Code readability in order: 1. Plus concatenation 2. string.Format 3. StringBuilder
  • 13. Conclusion • Use StringBuilder for performance critical code. • Use plus concatenation for simple cases. • In the case non-critical but a lot of string concatenations, use string.Format. • When confused, prioritize code readability over performance by default.