当我遇到一个有趣的结果时,我正在做一些有趣的实验计算:
Completed 1024x1024 pixels with 700 points in...
For Loop (Inline): 19636ms
For Loop: 12612ms
Parallel.For Loop: 3835ms
Run Code Online (Sandbox Code Playgroud)
这不是我的预期.
系统:Windows 7 64,i3 2120 [双核,4个线程],Visual Studio 2010.
构建:优化开启,释放模式[无调试器],32位.
次要的兴趣是令人失望的64位性能.虽然它更符合我对比率的预期,但它通过全面放慢来实现这一目标.
Completed 1024x1024 pixels with 700 points in...
For Loop (Inline): 23409ms
For Loop: 24373ms
Parallel.For Loop: 6839ms
Run Code Online (Sandbox Code Playgroud)
计算很简单:对于索引x和y找到最接近的Vector3并将其存储在2D数组中.
如果你敢,问题是试图解释为什么内联循环是如此缓慢.用于解释64位版本缺乏性能的奖励积分.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace TextureFromPoints
{
class Program
{
const int numPoints = 700;
const int textureSize = 1024;
static Random rnd = new Random();
static void Main(string[] args)
{ …Run Code Online (Sandbox Code Playgroud)