Why does C# execute Math.Sqrt() more slowly than VB.NET?

后端 未结 6 1542
情深已故
情深已故 2020-12-14 05:45

Background

While running benchmark tests this morning, my colleagues and I discovered some strange things concerning performance of C# code vs. VB.NET code.

6条回答
  •  感情败类
    2020-12-14 06:11

    Off on a tangent, if you're up and running with VS2010, you can take advantage of PLINQ and make C# (probably VB.Net as well) faster.

    Change that for loop to...

    var range = Enumerable.Range(2, 5000000);
    
    range.AsParallel()
        .ForAll(i => testIfPrimeSerial(i));
    

    I went from 7.4 -> 4.6 seconds on my machine. Moving it to release mode shaves a little more time on top of that.

提交回复
热议问题