I'm not 100% sure what it's doing, but I'd say lookup tables are the way to go. Also allocating a new Uint16Array each time around the loop isn't great - it'd be faster as a normal array.
Even something like:
var gdimlookup = {
15: function(i) {
if (ma <390 && mi < 300) {
this.gdim[i]=3;
return 10.33;
} else if (ma <700 && mi < 500) {
this.gdim[i]=7;
return 4.4;
} else if (ma <1700 && mi < 1000) {
this.gdim[i]=15;
return 2.06;
}
},
...
};
// ...
var f = gdimlookup[this.gdim[i]];
var mult = f?f(i):1;
would help, as it's not having to parse a whole bunch of stuff each time around the loop.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I'm not 100% sure what it's doing, but I'd say lookup tables are the way to go. Also allocating a new Uint16Array each time around the loop isn't great - it'd be faster as a normal array.
Even something like:
would help, as it's not having to parse a whole bunch of stuff each time around the loop.