Are all those arrays typed arrays? Accessing those should be quite quick, but accessing large, normal arrays is slow. Mind you, your arrays really aren't that large.
It also helps if all the variables you're accessing are defined in the function itself, but it looks like you're doing that.
Actually even finding a variable based on name is a bit slow, and for an array access you're finding at least 2 variables.
So something like b[i]=b[i]+(z[i]>b[i]?1:-1); would be faster as b[i]+=z[i]>b[i]?1:-1;
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.
Are all those arrays typed arrays? Accessing those should be quite quick, but accessing large, normal arrays is slow. Mind you, your arrays really aren't that large.
It also helps if all the variables you're accessing are defined in the function itself, but it looks like you're doing that.
Actually even finding a variable based on name is a bit slow, and for an array access you're finding at least 2 variables.
So something like
b[i]=b[i]+(z[i]>b[i]?1:-1);
would be faster asb[i]+=z[i]>b[i]?1:-1;
Compiled code is also potentially an option?