from time import time # импорт модуля времени # простая функция возведения в степень def power_1(x): power_1 = 0 start = time() power_1 = x**200000 end = time() total_1 = end - start return round(total_1,6) # простые операции сложения, для того что бы посчитать отдельно время операции power_1(1) + power_1(2) + power_1(3) + power_1(4) + power_1(5) + power_1(6) + power_1(7) + power_1(8) \ + power_1(9) + power_1(10)
from time import time #получаем модуль времени # функция итерации def power_2(): for i in range(11): yield i # функции возведения в степень for i in power_2(): if i < 11: d = 0 total_2 = 0 start = time() d += i**200000 end = time() total_2 += end - start print('Ineration {} lasts {}'.format(i, round(total_2, 6))) if i == 10: print(' \n End with total time {} \n'.format(round(total_2,3)))
def add_one(x): total_3 = 0 start = time() s = x + 1 end = time() total_3 += end - start print('Time to do add 1 to BIG number: {} \n'.format(total_3)) return print('Difference in time {}\n'.format(round(total_2 - total_3 ,3))) add_one(d) print('The size of the number {}!!!'.format(len(str(d))))
Source: https://habr.com/ru/post/439312/