+ 6

How to make addition of long numbers quicker

Please check out this piece of code: https://code.sololearn.com/cMo9E8sVzlp3/?ref=app Nice first draft, I think, but rather slow. Any ideas how to speed up it? Thanks a lot! 😊

19th May 2017, 7:17 AM
Senfman
Senfman - avatar
2 Antworten
+ 5
This makes a lot of sense!! 😊 Thanks a lot for your answer, Venkatesh! I will now definitely try out multithreating. Never done this before though...
23rd May 2017, 7:14 AM
Senfman
Senfman - avatar
+ 1
Python's source code should definitively answer this. Until I find it, here is a stab. You are adding one digit at a time, whereas the built-in should be chopping up the long number into CPU word-sized chunks, sending off one chunk per process/thread, and putting the results back together. Effectively, you are filling up 8 bits out of say, 64 and adding one pair at a time.
23rd May 2017, 1:41 AM
Venkatesh Pitta
Venkatesh Pitta - avatar