如何加快C#中的阵列克隆?
发布时间:2020-12-15 18:10:18 所属栏目:百科 来源:网络整理
导读:我正在努力解决 Cult of the Bound Variable问题. 您的一部分问题已经为“古代”通用机器实施了解释器.我已经为他们描述的机器执行了一个口译,现在我正在运行大学提供的测试基准程序. 我的C#实现这个解释器很慢! 我在ANTS分析器中启动了我的程序,以查看减速
我正在努力解决
Cult of the Bound Variable问题.
您的一部分问题已经为“古代”通用机器实施了解释器.我已经为他们描述的机器执行了一个口译,现在我正在运行大学提供的测试基准程序. 我的C#实现这个解释器很慢! 我在ANTS分析器中启动了我的程序,以查看减速的位置,我可以看到,超过96%的时间被“加载程序”操作所占用. 该操作符的specification如下: #12. Load Program. The array identified by the B register is duplicated and the duplicate shall replace the '0' array,regardless of size. The execution finger is placed to indicate the platter of this array that is described by the offset given in C,where the value 0 denotes the first platter,1 the second,et cetera. The '0' array shall be the most sublime choice for loading,and shall be handled with the utmost velocity. 这是我的这个操作符的代码: case 12: // Load Program _platters[0] = (UInt32[])_platters[(int)_registers[B]].Clone(); _finger = _registers[C]; break; 我的整个“通用机器”口译的源代码是here. 我能做些什么来做得更快?此解释器还有其他C语言编写,可以更快地完成整个基准测试. 解决方法
您可以尝试使用
Buffer.BlockCopy ,但如果在这种情况下产生巨大差异,我会感到惊讶:
case 12: // Load Program uint[] src = _platters[(int)_registers[B]]; _platters[0] = new uint[src.Length]; Buffer.BlockCopy(src,_platters[0],src.Length * 4); _finger = _registers[C]; break; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |