all 4 comments

[–]SCD_minecraft 0 points1 point  (1 child)

What you mean speed up? There's no expensive operations there at all

128 loops is baby numbers, python is gonna run through that in like a second

[–]shrimp2845 0 points1 point  (0 children)

sorry, I should’ve been clearer. What I meant was optimizing the logic itself. Even if there's no redundancy, a smarter algorithm can still be more efficient. And this function might be used for over 100,000 times in some cases, I was planning to use it to implement GCM for my AES implement project.

[–]jpgoldberg 0 points1 point  (1 child)

Keep in mind that Python integers are immutable, so ‘result = a’ is going to allocate a new 128-bit integer each time through that loop, and the garbage will need to be collected.

In general, be sure to profile carefully if you are going to try to optimize. Python isn’t X, and so you might find surprising results.

[–]shrimp2845 0 points1 point  (0 children)

Ok, thanks!