安装需要编译器。如果在 Windows 平台,需要自行先安装 C++ 编译器。如果不想装麻烦的 VC++,可以转而在 这里 下载别人编译好的 .whl 安装包。在 Linux/Mac 上面就简单很多,编译环境肯定有的。 最近发现新版的已经不需要了,Windows 也有了编译好的包,可以直接安装。
使用
在需要 profile 的函数前,加上”@profile”,例如下面的 xxxxxx.py:
@profile
def main():
l = [i for i in range(10000)]
s = set(l)
for _ in range(1000):
if 9876 in l:
pass
if 9876 in s:
pass
if __name__ == '__main__':
main()
经过一点使用,了解到 @profile 的用法有一点限制,不可以对 class 打标签,但是可以打在 class 的方法上;子函数也可以用;并且可以同时 profile 多个函数 。
然后,运行:
kernprof -v -l xxxxxx.py
我们就得到了结果:
Wrote profile results to xxxxxx.py.lprof
Timer unit: 1e-06 s
Total time: 0.076552 s
File: xxxxxx.py
Function: main at line 2
Line # Hits Time Per Hit % Time Line Contents
==============================================================
2 @profile
3 def main():
4 1 965.0 965.0 1.3 l = [i for i in range(10000)]
5 1 792.0 792.0 1.0 s = set(l)
6
7 1001 1278.0 1.3 1.7 for _ in range(1000):
8 1000 71133.0 71.1 92.9 if 9876 in l:
9 pass
10 1000 1297.0 1.3 1.7 if 9876 in s:
11 1000 1087.0 1.1 1.4 pass
import yfinance as yf
msft = yf.Ticker("MSFT")
# get stock info
msft.info
# get historical market data
hist = msft.history(period="max")
# show actions (dividends, splits)
msft.actions
# show dividends
msft.dividends
# show splits
msft.splits
# show financials
msft.financials
msft.quarterly_financials