Friday, August 13, 2010

String vs StringBuilder

I know this, but I am making a note here.. just to make sure

String += is immutable. Thus, every += requires new object creation - memory dump and swap.
not good.

StringBuilder .Append() creates an object then appends.

StringBuilder is preferable when concat() the strings together.

performance data is here

String Concat

string s1 = "hello";
s1 += "Pulled functionalities web C# .NET applications with new codes from Lotus Notes/Domino applications.";
s1 += "Created Java web services on the Domino servers 7.0 to exchange data and use servers’ functionalities like the name lookup, sending emails, and querying and aggregating various Domino data to C# .NET applications.";
s1 += "Transposed Domino applications’ data definitions to created similar data tables on SQL servers 2005/2008.";
s1 += "Created similar look and feel in C# ASP.NET applications with new codes from the Domino applications.";
s1 += "Created membership, hierarchy, and accounting algorithms for workflow applications.";
s1 += "Created business and data objects that are exposed as C# WCF services to C# ASP.NET applications that are mobile devices and differing browsers friendly with advanced CSS techniques. Every single application I developed had C# WCF implemented. ";
s1 += "Created video tutorials and help documentations for some projects. Created code documentations for all my projects.";
s1 += "Used jQuery/Ajax for the user interface on all projects.";
s1 += "Implemented generic methods to create common web controls that can be used in different applications in C#.";
s1 += "Created C# Silverlight applications and web services. ";
s1 += "Developed some parts of applications with the MVC. However, by the time the MVC came as a real production solution from Microsoft, I was already doing many of the MVC practices.";
s1 += "Created error reporting services that capture errors within codes during application events. ";
s1 += "Created RSS feeds for the Message Center, Error Report, Requisition, and Review System projects.";
s1 += "Organized and consolidated codes, used delegates to factor out common methods. Used reflections to identify data types at the core business object levels to handle data. Created configurator class to read, write, and query key values in .config files. ";
s1 += "Implemented and followed the “Code Complete” and “Patterns and Practices” prescribed by Microsoft.";
s1 += "URL Rewrite enabled.";

s1.Dump();

s1.Dump();

took 0.007 on LINQPad 4

StringBuilder

StringBuilder oSB = new StringBuilder();
oSB.Append("Pulled functionalities web C# .NET applications with new codes from Lotus Notes/Domino applications.");
oSB.Append("Created Java web services on the Domino servers 7.0 to exchange data and use servers’ functionalities like the name lookup, sending emails, and querying and aggregating various Domino data to C# .NET applications.");
oSB.Append("Transposed Domino applications’ data definitions to created similar data tables on SQL servers 2005/2008.");
oSB.Append("Created similar look and feel in C# ASP.NET applications with new codes from the Domino applications.");
oSB.Append("Created membership, hierarchy, and accounting algorithms for workflow applications.");
oSB.Append("Created business and data objects that are exposed as C# WCF services to C# ASP.NET applications that are mobile devices and differing browsers friendly with advanced CSS techniques. Every single application I developed had C# WCF implemented. ");
oSB.Append("Created video tutorials and help documentations for some projects. Created code documentations for all my projects.");
oSB.Append("Used jQuery/Ajax for the user interface on all projects.");
oSB.Append("Implemented generic methods to create common web controls that can be used in different applications in C#.");
oSB.Append("Created C# Silverlight applications and web services. ");
oSB.Append("Developed some parts of applications with the MVC. However, by the time the MVC came as a real production solution from Microsoft, I was already doing many of the MVC practices.");
oSB.Append("Created error reporting services that capture errors within codes during application events. ");
oSB.Append("Created RSS feeds for the Message Center, Error Report, Requisition, and Review System projects.");
oSB.Append("Organized and consolidated codes, used delegates to factor out common methods. Used reflections to identify data types at the core business object levels to handle data. Created configurator class to read, write, and query key values in .config files. ");
oSB.Append("Implemented and followed the “Code Complete” and “Patterns and Practices” prescribed by Microsoft.");
oSB.Append("URL Rewrite enabled.");

oSB.ToString().Dump();

0.008 seconds...

I have this result maybe due to the fact that the data size is small.


No comments: