Profile your code
Research in the field of Structural Design is more about developing concepts than implementations. If a concept is sound, the details of the implementation can be figured out later, by someone with more computational and/or programming experience.
Of course, while developing concepts and approaches, we need some kind of implementation to test and prove they actually work. And, let’s face it, we all like writing reasonably fast and robust implementations. Therefore, at one point or another, we all rewrite code to optimise and make it run faster.
In my experience, the slowest part of your code is almost never the part you imagined. Profiling your code before optimising will save you a lot of work.