我在玩 couchdb 和推荐的“couchdbkit”python 包。我觉得它有点慢,并决定做一些测量。如果我没有做错什么,那么使用流行的“请求”包比通过 couchdbkit 快 10 倍以上。为什么?
这是我使用的计时脚本:
from time import time as now
from pprint import pprint
class Timer:
def __init__(self):
self.current = now()
def __call__(self, msg):
snap = now()
duration = snap - self.current
self.current = snap
pprint("%.3f duration -- %s" %(duration, msg))
def requests(num):
t = Timer()
import requests
for i in range(num):
r = requests.get("http://127.0.0.1:8001/releases/_design/access/_view/yieldlinks")
assert r.status_code == 200
r.json # make sure the json is there
t("requests: %d" % (num,))
def couchdbkit(num):
import couchdbkit
t = Timer()
server = couchdbkit.Server("http://127.0.0.1:8001")
releases = server.get_db("releases")
for x in range(num):
for x in releases.view("access/yieldlinks"):
pass
t("couchdbkit: %d" %(num,))
num = 500
requests(num)
couchdbkit(num)
要运行该示例,您可能需要修改视图 URL。我验证了这两个调用在服务器上导致完全相同的 GET 请求。所以这似乎真的与couchdbkit的内部工作有关?!