java - Why is my Android Thread so Slow? -


i have been trying write poker scoring algorithm... has 7 nested for-loops iterate through every combination of 7 card poker hands , score them. of course pretty intensive loop... under 110.5 million combinations.

my algorithm raw work in progress... manages correctly score hand combinations in 8.5 seconds in eclipse on desktop. not bad thought... same algorithm in android thread takes 17 minutes on android emulator , 4 minutes on htc 1 xl.

i prepared phone run slower newish desktop... not factor of 30.

my code below;

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() {     (c = 0; c < 8192; c++)     {         bitstring = string.format("%13s", integer.tobinarystring(c)).replace(" ","0");      }      stime = system.currenttimemillis();     pips[0] = 8191;      (c1 = 0;      c1 < 46; c1++) {     (c2 = c1 + 1; c2 < 47; c2++) {     (c3 = c2 + 1; c3 < 48; c3++) {     (c4 = c3 + 1; c4 < 49; c4++) {     (c5 = c4 + 1; c5 < 50; c5++) {      (c6 = c5 + 1; c6 < 51; c6++) {     (c7 = c6 + 1; c7 < 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 

am doing wrong implementing threads in android?

i'm worried may size of byte , boolean arrays , sort of memory limit imposed on thread?

the problem not threads.

the problem not memory usage ... because looks relatively small, , (afaik) doesn't change in part of code work being done.

the real problem have 7-level deep loop substantial range on each variable , doing lot of work inside loop.

(hint: 46 * 47 * 48 * 49 * 50 * 51 * 52 ... rather large number.)

and basically, pc can run java code lot faster typical mobile phone. factor of 30 plausible me.


one thing take consideration jit compiler in hotspot jvm more sophisticated , more "aggressive" typical android jit compiler. if anything, going magnify difference in hardware performance.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -