python計算收益率的效率分析-sympy包-計算呈指數遞增,大量計算不考慮
阿新 • • 發佈:2019-02-12
from sympy import * import time import datetime for i in range(1,50): print('第'+str(i)+'次計算開始') x = Symbol('x') startTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) print(startTime) mystr='' for j in range(1,i+1): mystr+='+x**'+str(j) mystr=mystr[1:] xx=solve(eval(mystr)-1.1*i,x) endTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) print(endTime) startTime= datetime.datetime.strptime(startTime,"%Y-%m-%d %H:%M:%S") endTime= datetime.datetime.strptime(endTime,"%Y-%m-%d %H:%M:%S") seconds = (endTime- startTime).seconds print('第{}次方方程計算耗費的時間為{}秒'.format(i,seconds))