String PK StringBuilder is a legend. Only a hands-on experiment can give a definite answer.

Source: Internet
Author: User

String PK StringBuilder is a legend. Only a hands-on experiment can give a definite answer.
The test result of the local machine is as follows: In most cases, the string performance is not inferior to that of StringBuilder and only varies in special cases. It is not like the test result of some of the above friends, as long as StringBuilder is used, it must be superior to String. In addition, most testers do not consider the time and cost of memory allocation (because most of the memory is larger than 2 GB ). In this test, only the time running efficiency is considered, and the space cost is not considered. Test Conditions :. net 4.0 hardware: Tinkpad t540P, 4G memory win8.1 first method: Copy code 1 [TestClass] 2 public class StringTest1 3 {4 [TestMethod] 5 public void String1Test1 () 6 {7 for (int I = 0; I <1; I ++) 8 {9 string queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 10 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 11 queryString + =" order by p. name "; 12} 13} 14 [TestMethod] 15 public void String10Test1 () 16 {17 for (int I = 0; I <10; I ++) 18 {19 string queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 20 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 21 queryString + =" order by p. name "; 22} 23} 24 [TestMethod] 25 public void String100Test1 () 26 {27 for (int I = 0; I <100; I ++) 28 {29 string queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 30 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 31 queryString + =" order by p. name "; 32} 33} 34 [TestMethod] 35 public void String1000Test1 () 36 {37 for (int I = 0; I <1000; I ++) 38 {39 string queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 40 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 41 queryString + =" order by p. name "; 42} 43} 44 [TestMethod] 45 public void string1_test1 () 46 {47 for (int I = 0; I <10000; I ++) 48 {49 string queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 50 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 51 queryString + =" order by p. name "; 52} 53} 54 55 [TestMethod] 56 public void StringBuilder1Test1 () 57 {58 for (int I = 0; I <1; I ++) 59 {60 StringBuilder ssb = new StringBuilder (); 61 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 62 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 63 ssb. append ("order by p. name "); 64} 65} 66 [TestMethod] 67 public void StringBuilder10Test1 () 68 {69 for (int I = 0; I <10; I ++) 70 {71 StringBuilder ssb = new StringBuilder (); 72 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 73 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 74 ssb. append ("order by p. name "); 75} 76} 77 [TestMethod] 78 public void StringBuilder100Test1 () 79 {80 for (int I = 0; I <100; I ++) 81 {82 StringBuilder ssb = new StringBuilder (); 83 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 84 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 85 ssb. append ("order by p. name "); 86} 87} 88 [TestMethod] 89 public void StringBuilder1000Test1 () 90 {91 for (int I = 0; I <1000; I ++) 92 {93 StringBuilder ssb = new StringBuilder (); 94 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 95 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 96 ssb. append ("order by p. name "); 97} 98} 99 [TestMethod] 100 public void stringbuilder1_test1 () 101 {102 for (int I = 0; I <10000; I ++) 103 {104 StringBuilder ssb = new StringBuilder (); 105 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 106 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 107 ssb. append ("order by p. name "); 108} 109} 110} copy code method 2 Copy code 1 [TestClass] 2 public class StringTest2 3 {4 [TestMethod] 5 public void String1Test2 () 6 {7 string queryString = string. empty; 8 for (int I = 0; I <1; I ++) 9 {10 queryString = string. empty; 11 queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 12 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 13 queryString + =" order by p. name "; 14} 15} 16 [TestMethod] 17 public void String10Test2 () 18 {19 string queryString = string. empty; 20 for (int I = 0; I <10; I ++) 21 {22 queryString = string. empty; 23 queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 24 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 25 queryString + =" order by p. name "; 26} 27} 28 [TestMethod] 29 public void String100Test2 () 30 {31 string queryString = string. empty; 32 for (int I = 0; I <100; I ++) 33 {34 queryString = string. empty; 35 queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 36 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 37 queryString + =" order by p. name "; 38} 39} 40 [TestMethod] 41 public void String1000Test2 () 42 {43 string queryString = string. empty; 44 for (int I = 0; I <1000; I ++) 45 {46 queryString = string. empty; 47 queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 48 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 49 queryString + =" order by p. name "; 50} 51} 52 [TestMethod] 53 public void string1_test2 () 54 {55 string queryString = string. empty; 56 for (int I = 0; I <10000; I ++) 57 {58 queryString = string. empty; 59 queryString = @ "select p from DALParty as p where p. ownerID =: OwnerID "; 60 queryString + =" and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "; 61 queryString + =" order by p. name "; 62} 63} 64 65 [TestMethod] 66 public void StringBuilder1Test2 () 67 {68 StringBuilder ssb = new StringBuilder (); 69 for (int I = 0; I <1; I ++) 70 {71 ssb. clear (); 72 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 73 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 74 ssb. append ("order by p. name "); 75} 76} 77 [TestMethod] 78 public void StringBuilder10Test2 () 79 {80 StringBuilder ssb = new StringBuilder (); 81 for (int I = 0; I <10; I ++) 82 {83 ssb. clear (); 84 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 85 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 86 ssb. append ("order by p. name "); 87} 88} 89 [TestMethod] 90 public void StringBuilder100Test2 () 91 {92 StringBuilder ssb = new StringBuilder (); 93 for (int I = 0; I <100; I ++) 94 {95 ssb. clear (); 96 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 97 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 98 ssb. append ("order by p. name "); 99} 100} 101 [TestMethod] 102 public void StringBuilder1000Test2 () 103 {104 StringBuilder ssb = new StringBuilder (); 105 for (int I = 0; I <1000; I ++) 106 {107 ssb. clear (); 108 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 109 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 110 ssb. append ("order by p. name "); 111} 112} 113 [TestMethod] 114 public void stringbuilder1_test2 () 115 {116 StringBuilder ssb = new StringBuilder (); 117 for (int I = 0; I <10000; I ++) 118 {119 ssb. clear (); 120 ssb. append (@ "select p from DALParty as p where p. ownerID =: OwnerID "); 121 ssb. append ("and (p. name like: Name or p. code like: Name or p. taxCode like: Name) "); 122 ssb. append ("order by p. name "); 123} 124} 125}

Related Article

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.