title: Why is my Android Thread so Slow?
body: <p>I have been trying to write a poker scoring algorithm... which has seven nested for-loops to iterate through every combination of seven card poker hands and score them. It is of course a pretty intensive loop... with just under 110.5 million combinations.</p>
  
  <p>My algorithm is a raw work in progress... but manages to correctly score all the hand combinations in about 8.5 seconds in Eclipse on my Desktop. Not bad I thought... but the same algorithm in an Android thread takes 17 minutes on the Android emulator and 4 minutes on my HTC One XL.</p>
  
  <p>I was fully prepared for the phone to run slower than my newish desktop... but not by a factor of 30.</p>
  
  <p>My code is below;</p>
  
  <pre><code>public void startThread() {
  
    Runnable runnable = new Runnable()
    {
      String bitString;
      byte[] bitCount = new byte[8192];
      byte[] isStraight = new byte[8192];
      boolean[] isFlush = new boolean[8912];
  
      int c, c1, c2, c3, c4, c5, c6, c7;
      int[] cards = new int[7];
      long sTime, eTime, score = 0;
      int[] handCount = new int[9];
  
      int pipMask;
      int[] pips = new int[6];
      int[] suit = new int[4];
  
  @Override
  public void run()
  {
      for (c = 0; c &lt; 8192; c++)
      {
          bitString = String.format("%13s", Integer.toBinaryString(c)).replace(" ","0");
  
      }
  
      sTime = System.currentTimeMillis();
      pips[0] = 8191;
  
      for (c1 = 0;      c1 &lt; 46; c1++) {
      for (c2 = c1 + 1; c2 &lt; 47; c2++) {
      for (c3 = c2 + 1; c3 &lt; 48; c3++) {
      for (c4 = c3 + 1; c4 &lt; 49; c4++) {
      for (c5 = c4 + 1; c5 &lt; 50; c5++) { 
      for (c6 = c5 + 1; c6 &lt; 51; c6++) {
      for (c7 = c6 + 1; c7 &lt; 52; c7++) {
  
          --- code goes here ---
  
      }}}}}}}
  
      eTime = System.currentTimeMillis(); Log.d("end", "" + (eTime - sTime));
  
      message = handler.obtainMessage();
      bundle = new Bundle();
      bundle.putString("msgText", "Finished in " + (eTime - sTime));
      message.setData(bundle);
      handler.sendMessage(message);
  
    } // end run()
  
  }; // end runnable
  
  Thread myThread = new Thread(runnable); myThread.start();
  
  } // end
  </code></pre>
  
  <p>Am I doing something wrong with implementing Threads in Android?</p>
  
  <p>I'm worried it may be the size of the byte and boolean arrays and some sort of memory limit imposed on the Thread?</p>