0

Im developing a game based on a bunch of isometric tiles. I have the option to:

A:

for (i=0;i<numberoftiles;i++){

drawMap(canvas, i);

drawBuildings(canvas, i);

drawlivingbeings(canvas, i);

}

B:

for (i=0;i<numberoftiles;i++){

canvas.drawBitmap(maparray[i],.........)

 canvas.drawBitmap(buildingsarray[i],.........)

canvas.drawBitmap(peoplearray[i],.........)

}

Option A has the advantage of splitting the code into smaller segments, following good coding practice

Option B saves having to pass the Canvas Object for hundreds of times.

Which approach should I choose in terms of efficiency?

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
  • 1
    i've made some minor changes to your question, personally i just think the `what would you choose` just sounds too opinionated, but your question does seem to involve performance so that's what i changed it to – a_local_nobody Apr 14 '21 at 10:35
  • 2
    Neither. It's all pass-pointer-by-value, which means there's no copying or extra costs. At least none of significance - a function abstracting another function requires moving integer values one more time, but it's essentially insignificant. The JVM can probably optimize bits of your code to reduce that insignificant delay anyway – Zoe Apr 14 '21 at 12:14
  • 1
    Do you have a real performance problem you're trying to solve? Seems like a premature/microoptimization that is highly unlikely to have any impact. Why not profile/benchmark both pieces of code and see for yourself? See [performance rant](https://ericlippert.com/2012/12/17/performance-rant/) – ggorlen Apr 14 '21 at 14:52
  • The performance of my game was struggling quite a bit depending on map/chunk size so i wanted to improve optimization. Chunking did it, but implementing that after writing the entire game without chunks was a bit of a pain lol. Thanks for the answers guys – FiveJungYetNoSmite Apr 14 '21 at 19:53

0 Answers0