def query(): n = 100 with timer('%s times olo query' % n): for _ in xrange(n): OBen.query.filter(age=1).all() with timer('%s times peewee query' % n): for _ in xrange(n): list(PBen.select().where(PBen.age == 1)) with timer('%s times sqlalchemy query' % n): s = session() for _ in xrange(n): s.query(SBen).filter(SBen.age == 1).all()
def create(): n = 1000 attrs = dict(age=1, name='a', key='b') with timer('%s times olo create' % n, True): for _ in xrange(n): OBen.create(**attrs) with timer('%s times peewee create' % n, True): for _ in xrange(n): PBen.create(**attrs) with timer('%s times sqlalchemy create' % n, True): for _ in xrange(n): ben = SBen(**attrs) s = session() s.add(ben) s.commit()
def update(): n = 100 age = 1 with timer('%s times olo update' % n): ben = OBen.get_by(age=age) for age in xrange(age + 1, n + age + 1): ben.update(age=age) with timer('%s times peewee update' % n): ben = PBen.get(PBen.age == age) for age in xrange(age + 1, n + age + 1): ben.age = age ben.save() with timer('%s times sqlalchemy update' % n): s = session() ben = s.query(SBen).filter_by(age=age).first() for age in xrange(age + 1, n + age + 1): ben.age = age s.commit()
) if __name__ == '__main__': n = 100 pr = cProfile.Profile() pr.enable() for _ in xrange(n): r = OBen.query.filter(age=1).all() print(len(r)) pr.disable() pr.dump_stats('olo.prof') pr = cProfile.Profile() pr.enable() for _ in xrange(n): r = list(PBen.select().where(PBen.age == 1)) print(len(r)) pr.disable() pr.dump_stats('peewee.prof') pr = cProfile.Profile() pr.enable() s = session() for _ in xrange(n): r = s.query(SBen).filter(SBen.age == 1).all() print(len(r)) pr.disable() pr.dump_stats('sqlalchemy.prof')