Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time complexity of int
#6
Python does use an improved algorithm for squaring large numbers. The improvement just decreases the constant so the time complexity doesn't change. The improvement is measurable.

a is 1232 bits long.

$ py38 -m timeit -s "a=3**777 + 7**123; b=a+11**7" "a*b"
200000 loops, best of 5: 1.49 usec per loop
$ py38 -m timeit -s "a=3**777 + 7**123; b=a+11**7" "a*a"
200000 loops, best of 5: 1.09 usec per loop
Now a is 123274 bit long.

$ py38 -m timeit -s "a=3**77777 + 7**12345; b=a+11**7" "a*a"
100 loops, best of 5: 2.58 msec per loop
$ py38 -m timeit -s "a=3**77777 + 7**12345; b=a+11**7" "a*b"
100 loops, best of 5: 2.98 msec per loop
Reply


Messages In This Thread
time complexity of int - by Skaperen - Jul-03-2020, 11:18 PM
RE: time complexity of int - by casevh - Jul-04-2020, 08:28 PM
RE: time complexity of int - by Skaperen - Jul-05-2020, 12:08 AM
RE: time complexity of int - by casevh - Jul-05-2020, 05:06 AM
RE: time complexity of int - by Skaperen - Jul-05-2020, 05:58 AM
RE: time complexity of int - by casevh - Jul-05-2020, 03:03 PM
RE: time complexity of int - by Skaperen - Jul-05-2020, 06:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Time complexity different between operating systems. Why? Mekire 2 4,269 Jan-18-2017, 09:29 PM
Last Post: casevh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020