Knight’s Tour

Written by Ryan on December 22nd, 2009

I wrote a little program to calculate the “winning” boards of the Knight’s Tour problem after my grandfather brought it up and noticed some C# array performance stats while I was at it. I ended up using lots of .Clone() operations on the arrays and just some basic index accessing.

On the first try, I wrote it with a multidimensional int[,] array and it took 48.5s to run 10M iterations. After reading that you should really flatten multidimensional arrays, and changing the code to just use int[], it only took 10.2s to run otherwise identical code. That’s pretty huge.

Out of curiosity, I switched it again to use ArrayList objects and knocked it even further down to 6.4s.

So, multidimensional arrays, slow! ArrayLists, fast! Is anything else better?

 

2 Comments so far ↓

  1. Fantastic beat ! I wish to apprentice while you amend your site, how could i subscribe for a blog web site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear concept

  2. Hey just wanted to give you a quick heads up.
    The words in your article seem to be running off the screen in Firefox.

    I’m not sure if this is a format issue or something to do with
    web browser compatibility but I thought I’d post to let you know.
    The layout look great though! Hope you get the
    issue fixed soon. Cheers

Leave a Comment