>  기사  >  데이터 베이스  >  MongoDB性能测试与Python测试代码

MongoDB性能测试与Python测试代码

WBOY
WBOY원래의
2016-06-07 17:11:48951검색

下面是对mongodb测试的代码和结果。虽然公司用的一水的CentOS,但是由于我是FreeBSD的支持者,所以在FreeBSD和CentOS上都测试了一

#!/usr/bin/env python

from pymongo import Connection
import time,datetime

connection = Connection('127.0.0.1', 27017)
db = connection['hawaii']

def func_time(func):
        def _wrapper(*args,**kwargs):
                start = time.time()
                func(*args,**kwargs)
                print func.__name__,'run:',time.time()-start
        return _wrapper

@func_time
def remove():
        posts = db.userinfo
        print 'count before remove:',posts.count();
        posts.remove({});
        print 'count after remove:',posts.count();

if __name__ == "__main__":
        remove()

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.