in reply to Initialize a 2D array with zeros
EDIT: To make it slightly more efficient, the "width" of your array should be a power of 2. So, instead of 1000 x 1000, you'd create 1024 x 1000, and then you would access any value in the array by doing this instead: vec($str, $Y << 10 | $X, 8) The only difference is that now we use the bitwise << shift operator and | OR operator in the calculation instead of multiplication and addition. When you use multiplication, Perl assumes that you're multiplying a 64-bit double, so it executes the FMUL function which is slow. But when you do bitwise operations, your calculation is classified as integer math which is way faster, especially when you have to do millions of calculations.
|
---|