标签:
对比用的代码
主要是直接使用string的+ 和用内置字符串合并方法的比较
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");
打印结果
55.0031 1.0001
结果是:内置方法完胜字符串加法,合并次数越多越明显。
标签:
原文地址:http://my.oschina.net/000quanwei/blog/497049