In [1]:
import random
import time
In [2]:
def f(max_a, max_b):
    A = [random.randint(1, max_a) for _ in range(10 ** 6)]
    B = [random.randint(1, max_b) for _ in range(10 ** 6)]
    
    t0 = time.time()
    for a, b in zip(A, B):
        q, r = divmod(a, b)
    t1 = time.time()
    
    dm = divmod
    for a, b in zip(A, B):
        q, r = dm(a, b)
    t2 = time.time()
    
    for a, b in zip(A, B):
        q, r = a // b, a % b
    t3 = time.time()
    
    for a, b in zip(A, B):
        q = a // b; r = a - q * b
    t4 = time.time()
    
    print('[divmod] {:.4f}sec, [dm = divmod] {:.4f}sec, [// and %] {:.4f}sec, [// and -*] {:.4f}sec'.format(t1-t0, t2-t1, t3-t2, t4-t3))
In [3]:
f(1 << 8, 1 << 4)
f(1 << 32, 1 << 16)
f(1 << 64, 1 << 32)
f(10 ** 100, 10 ** 50)
f(10 ** 1000, 10 ** 500)
[divmod] 0.0957sec, [dm = divmod] 0.0868sec, [// and %] 0.0578sec, [// and -*] 0.0668sec
[divmod] 0.1346sec, [dm = divmod] 0.1247sec, [// and %] 0.1346sec, [// and -*] 0.1356sec
[divmod] 0.1825sec, [dm = divmod] 0.1715sec, [// and %] 0.2194sec, [// and -*] 0.2134sec
[divmod] 0.3092sec, [dm = divmod] 0.2952sec, [// and %] 0.4638sec, [// and -*] 0.3939sec
[divmod] 4.3833sec, [dm = divmod] 4.3883sec, [// and %] 8.6638sec, [// and -*] 7.4052sec