對比用的代碼 sql
主要是直接使用string的+ 和用內置字符串合併方法的比較 c#
Random rand=new Random(); byte[] a = new byte[10000]; for (int i = 0; i < a.Length; ++i) a[i] = (byte)rand.Next(256); DateTime now1 = DateTime.Now; string s1 = ""; for (int i = 0; i < a.Length; ++i) s1 += Convert.ToString(a[i], 16)+" "; DateTime end1 = DateTime.Now; DateTime now2 = DateTime.Now; List<string> s2=new List<string>(); for (int i = 0; i < a.Length; ++i) s2.Add(Convert.ToString(a[i], 16)); string s3 = string.Join(" ", s2.ToArray()); DateTime end2 = DateTime.Now; MessageBox.Show((end1 - now1).TotalMilliseconds.ToString() + " : " + "\n" + (end2 - now2).TotalMilliseconds.ToString() + " : " + "\n");
打印結果 dom
55.0031 1.0001
結果是:內置方法完勝字符串加法,合併次數越多越明顯。 code