有没有人注意到 praw 的 get_redditor() 方法有点慢?我昨天开始使用它,当我开始注意到速度下降时,我决定做一些测试。我使用以下代码:
import praw
import time
time1 = 0
time2 = 0
print('Initial reddit setup')
time1 = int(round(time.time() * 1000))
user_agent = ('Reddit Checker 0.1 by /u/NinjaXI')
r = praw.Reddit(user_agent)
time2 = int(round(time.time() * 1000))
print(time1)
print(time2)
print(time2 - time1)
print('===================================================================')
print('Get Subreddit Python')
time1 = int(round(time.time() * 1000))
pythonSub = r.get_subreddit('Python')
time2 = int(round(time.time() * 1000))
print(time1)
print(time2)
print(time2 - time1)
print('===================================================================')
print('Get hot 10')
time1 = int(round(time.time() * 1000))
pythonSub.get_hot(limit=10)
time2 = int(round(time.time() * 1000))
print(time1)
print(time2)
print(time2 - time1)
print('===================================================================')
print('Get Redditor NinjaXI')
time1 = int(round(time.time() * 1000))
me = r.get_redditor('NinjaXI')
time2 = int(round(time.time() * 1000))
print(time1)
print(time2)
print(time2 - time1)
print('===================================================================')
print('Get submitted 10')
time1 = int(round(time.time() * 1000))
me.get_submitted(limit=10)
time2 = int(round(time.time() * 1000))
print(time1)
print(time2)
print(time2 - time1)
print('===================================================================')
这输出:
Initial reddit setup
1421319134782
1421319134783
1
===================================================================
Get Subreddit Python
1421319134783
1421319134783
0
===================================================================
Get hot 10
1421319134783
1421319134783
0
===================================================================
Get Redditor NinjaXI
1421319134783
1421319137402
2619
===================================================================
Get submitted 10
1421319137402
1421319137402
0
===================================================================
如您所见,使用 get_redditor() 比 get_subreddit() 需要(在此运行中)多 2.6 秒。平均每次时间在 2 到 2.6 秒之间,但 get_subreddit() 仅高达 1 毫秒。我在做什么吗?这是 praw/reddit api 的已知问题吗?我有什么办法可以加快速度吗?