optimize split_matrix function#12552
Conversation
…act_submatrix function, add tests
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…of github.com:ivanz851/Algorithms-Python into reduce_cyclomatic_complexity_of_split_matrix_function
|
This increases readability and maintainability of the code, but certainly does not "optimize" the algorithm, for you have added the extra overhead of calling a function, which will actually slow down the algorithm. |
Actually, my code with extract_submatrix function is not less efficient than the original one, since there is exactly same number of conditional jumps. This can be checked using godbolt.org: comparison. If you follow the link, you can see disassembly of my revision of the code on the left and of the original code on the right. In original code, there are 8 FOR_ITER jumps and 8 JUMP_BACKWARD jumps. In new code, there are 2 FOR_ITER jumps and 2 JUMP_BACKWARD jumps in extract_submatrix function, which is called 4 times, so in sum we have same 8 FOR_ITER jumps and 8 JUMP_BACKWARD jumps. That's why I think code with extract_submatrix function is not slower and can be used for better readability. |
|
@ivanz851 Thanks, I learned something new today. Cheers |
I optimized split_matrix function by removing duplicate code to the extract_submatrix function, and added tests to test_strassen_matrix_multiplication.py file