測試條件: 依次計算1到100 0000的Math.Pow運算。運算3次。html
測試代碼:ide
static int maxNum = 1000000; static void Main(string[] args) { //迭代次數 int iterationNum = 3; CodeTimer.Initialize(); CodeTimer.Time("普通循環計算", iterationNum, new Action(NormalCompute)); CodeTimer.Time("1次並行循環計算", iterationNum, new Action(ParallelCompute_1)); CodeTimer.Time("2次並行循環計算", iterationNum, new Action(ParallelCompute_2)); Console.Read(); } private static void NormalCompute() { for (int i = 1; i <= maxNum; i++) { Math.Pow(i, i + 1); } } private static void ParallelCompute_1() { Parallel.For(1, maxNum, (i) => { Math.Pow(i, i + 1); }); } private static void ParallelCompute_2() { Parallel.For(1, maxNum / 2, (i) => { Math.Pow(i, i + 1); }); Parallel.For(maxNum / 2 + 1, maxNum, (i) => { Math.Pow(i, i + 1); }); }
測試結果:工具
http://blog.zhaojie.me/2009/03/codetimer.html性能
老趙的性能測試工具測試