Which one is more better, directly setting variables or API?

Post Reply
jinoh67
Posts: 4
Joined: Sat May 04, 2013 4:18 am

Which one is more better, directly setting variables or API?

Post by jinoh67 » Sat May 04, 2013 4:48 am

I want to optimize my code, but I don't know which is more faster and uses less memory.
If I use variables (uhh, maybe registers?) like OAM or OAM_SUB, It will be more than one statement and thus uses more ROM memory than using API (like oamSet). However, oamSet is a function and it will use call stack, and I have to use oamUpdate to apply the changes so it might be a little more slow :-P
So which is better, variable or API?

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Which one is more better, directly setting variables or

Post by elhobbs » Tue May 07, 2013 2:24 am

a few questions:
why do you want to optimize your code?
Is it running too slowly?
Is so, then where is it running too slowly?
Why do the think it is running slowly in this section?
Are you running out of memory?
If so, then how much free memory do you have, and how much more do you need?

running faster and using less memory are two separate and independent goals. However, doing one frequently sacrifices the other.

I am not really sure what you are asking in regards to variables and APIs. Are you asking if setting registers directly is better than using the libnds API for sprites? I suspect that you will find little difference (if any at all) in the performance either way. Since the libnds APIs are easier to understand - I would say they are better - until/unless you can prove why they are not.

Do not worry about this level of performance unless you need to.

jinoh67
Posts: 4
Joined: Sat May 04, 2013 4:18 am

Re: Which one is more better, directly setting variables or

Post by jinoh67 » Fri May 10, 2013 3:40 pm

elhobbs wrote:a few questions:
why do you want to optimize your code?
Is it running too slowly?
Is so, then where is it running too slowly?
Why do the think it is running slowly in this section?
Are you running out of memory?
If so, then how much free memory do you have, and how much more do you need?

running faster and using less memory are two separate and independent goals. However, doing one frequently sacrifices the other.

I am not really sure what you are asking in regards to variables and APIs. Are you asking if setting registers directly is better than using the libnds API for sprites? I suspect that you will find little difference (if any at all) in the performance either way. Since the libnds APIs are easier to understand - I would say they are better - until/unless you can prove why they are not.

Do not worry about this level of performance unless you need to.
Ah, yes, I know OAM APIs push all the changes in oamUpdate() which are saved by other oam functions, but registers apply changes immediately. Okay, I'll use the way that best fits in my code. By the way, It is better to replace some of calls of <video.h> functions to directly setting registers because the functions aren't complex and just cost some call stack :) (It is not true if they're "inline")

sverx
Posts: 94
Joined: Wed Aug 12, 2009 2:56 pm
Location: github.com/sverx
Contact:

Re: Which one is more better, directly setting variables or

Post by sverx » Thu May 16, 2013 12:11 pm

If you write to OAM or OAM_SUB, you're updating sprites 'immediately' (meaning in the current frame) while using libnds APIs, you're 'preparing' OAMs for an update that you'll do later, probably right when VBlank starts. This is however not really related to performance, but it is surely related to program logic...

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests