Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I speed up array cloning in C#?
    text
    copied!<p>I'm working on my solution to the <a href="http://www.boundvariable.org/task.shtml" rel="nofollow noreferrer">Cult of the Bound Variable</a> problem.</p> <p>Part of the problem has you implement an interpreter for the "ancient" Universal Machine. I've implemented an intepreter for the machine they describe and now I'm running a benchmark program that the university provided to test it.</p> <p>My C# implementation of this interpreter is <strong>slow</strong>!</p> <p>I fired up my program in the ANTS profiler to see where the slowdown is and I can see that over 96% of my time is taken up by the "Load Program" operation.</p> <p><img src="https://i.stack.imgur.com/LGAIw.png" alt="ANTS Profile Results"></p> <p>The <a href="http://www.boundvariable.org/um-spec.txt" rel="nofollow noreferrer">specification</a> of this operator is as follows:</p> <pre><code> #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. </code></pre> <p>Here is my code for this operator:</p> <pre><code>case 12: // Load Program _platters[0] = (UInt32[])_platters[(int)_registers[B]].Clone(); _finger = _registers[C]; break; </code></pre> <p>The source code to my whole "Universal Machine" interpreter is <a href="https://gist.github.com/1035661" rel="nofollow noreferrer">here</a>.</p> <p>What can I do to make this faster? There are other implementations of this interpreter written in C which complete the entire benchmark significantly faster.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload