Created
November 3, 2015 20:11
-
-
Save NickCraver/fce9754c50aa7a4c9593 to your computer and use it in GitHub Desktop.
string.Format() vs string.Concat() quick perf tests for Abstractions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string.Concat(): 3011 ms | |
| string.Format(): 18337 ms | |
| string.Concat(): 2885 ms | |
| string.Format(): 18312 ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string combinePath = "test"; | |
| string query = "test2"; | |
| string fragment = "test3"; | |
| int iterations = 100000000; | |
| string s; | |
| var sw = Stopwatch.StartNew(); | |
| for (var i = 0; i < iterations; i++) { s = combinePath + query.ToString() + fragment.ToString(); } | |
| sw.Stop(); | |
| Console.WriteLine($"string.Concat(): {sw.ElapsedMilliseconds} ms"); | |
| sw.Restart(); | |
| for (var i = 0; i < iterations; i++) { s = $"{combinePath}{query.ToString()}{fragment.ToString()}"; } | |
| sw.Stop(); | |
| Console.WriteLine($"string.Format(): {sw.ElapsedMilliseconds} ms"); | |
| sw.Restart(); | |
| for (var i = 0; i < iterations; i++) { s = combinePath + query.ToString() + fragment.ToString(); } | |
| sw.Stop(); | |
| Console.WriteLine($"string.Concat(): {sw.ElapsedMilliseconds} ms"); | |
| sw.Restart(); | |
| for (var i = 0; i < iterations; i++) { s = $"{combinePath}{query.ToString()}{fragment.ToString()}"; } | |
| sw.Stop(); | |
| Console.WriteLine($"string.Format(): {sw.ElapsedMilliseconds} ms"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment