测试条件: 依次计算1到100 0000的Math.Pow运算。运算3次。
测试代码:
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
老赵的性能测试工具
时间: 2024-11-06 18:46:40