# -*- coding: utf-8 -*-
"""
Created on Mon Jul 22 10:57:47 2019
@author: Administrator
"""
import pandas as pd
import numpy as np
import talib
import time
close_price = np.random.random(100000000)
print(close_price)
start = time.process_time()
talib.SMA(close_price, timeperiod=20)
end = time.process_time()
print("\n talib 计算耗时:")
print('耗时 %6.3f' %(end - start))
# 创建 dataframe
df = pd.DataFrame(close_price, columns=['close_price'])
#print(df.head())
start = time.process_time()
df.rolling(20).mean()
end = time.process_time()
print("\n DataFrame 计算耗时:")
print('耗时 %6.3f' %(end - start))
运行:
talib 计算耗时:
耗时 0.452
DataFrame 计算耗时:
耗时 4.976