I am in the middle of creating a Makecode extension with lots of useful graphics/pixel routines for the Pomoroni 119-bit LED display.
As part of this I am using look-up tables to speed up the computation for the location of pixel because the LEDs in the array are in an awkward order.
So in Makecode/JS, I have a constant as an array:
const COLUMN_MAP: number[] = [16, 14, 12, 10, 8, 6, 4, 2, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17]
But it is also possible to define a look-up function in a .cpp file
const int column_map[] = {16, 14, 12, 10, 8, 6, 4, 2, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17};
int COL_MAP(int x)
{
return column_map[x];
}
My question is this: why is it that if the look-up table is 18 bytes long it is quicker to do this directly in MakeCode, whereas if the look-up table is 127 bytes long it appears to be faster to execute if you define it in C using a .cpp file within the extension?