Main Site Documentation

MathEx.Sin Vs. Lookup table


#1

I’m currently trying to optimize a program I’ve created on my FEZ Panda II. Along with running a music shield and a few other things, it is PWM controlling two sets of RGB LED strips, and one of the modes slowly pulsates the LEDs using MathEx.Sin.

I was wondering if anyone knows off hand weather I am better off just using the MathEx.Sin function or creating a lookup table. It would probably end up being an array of 50 doubles to get the resolution I want.

I’ve done a little searching around on the web, and it seems that people are saying that when they bench marked it, using Sin is faster… but this is on computer applications, and I don’t know if it is true for the USBizi.


#2

You’d probably want to benchmark it. Know that using a lookup table generally trades memory (by using more) for CPU time (by using less). Don’t assume anything, though, try it on your own.


#3

Yeah I already figured it would use more memory… but then again I won’t have to include GHIElectronics.NETMF.System in my project if I use the lookup table, so I might gain some memory there?

Hmmm… I was hoping somebody had tried this in a project before. I could benchmark it with a simple purpose written program, but since mine has a lot of different stuff going on it might work differently there.


#4

You’d gain flash memory by not including the reference, but that’s not the same as RAM.

This is all why the #1 rule of optimization is this:

Don’t.

Rule #2, for EXPERTS ONLY, is this:

Don’t, yet.


#5

I’m not all that experienced of a programmer yet as you can tell, but if I’m constantly using that extra reference wouldn’t that be entering in to RAM? Or is RAM just holding variables I’m using?

It sounds like you are saying to just not worry about it… which I can appreciate. This project is just a learning process that keeps evolving, so I thought as it got more complex I’d look around for ways to generally improve performance.

Thanks for your thoughts.


#6

The rules of optimization don’t say “don’t worry about it”, what they’re really saying is, “don’t worry about it unless it is actually a problem, and you know exactly what’s causing the problem”. Otherwise, you end up spending all your time optimizing things that won’t matter :slight_smile:

If the Sin() is causing a performance slowdown, then by all means, investigate ways to make it faster. Otherwise, spend your time adding features :slight_smile: