On Aug 18, 2010, at 4:16 PM, Michael Hipp wrote:
> The little diddly below is comparing performance of orm access vs sql
> expression language.
>
> When I run it with number=1 I get a 5.8x advantage for sql. When I run it 10
> times I get a 2.7x advantage. The actual numbers are, respectively:
>
> 1.47375132
> 0.25630808
>
> 5.45569524
> 1.96911144
>
> Is this a typical/expected difference in performance between the two query
> methods?
Whats important to note is that the ORM is providing state-managed proxy
objects, keyed on an identity map, which will faithfully represent the correct
state in the transaction at all times. A resultset is just a quick tuple.
I've done some "competetive testing" recently around the unit-of-work capable
Python ORM field, I'll leave it as an exercise who it is we "compete" with, and
we are still close to the same speed for small result sets and still faster for
large result sets (and still with all the other performance enhancing features
like eager loads that aren't possible with the competition). So we're doing
very well.
>
> Michael
>
>
>
> def timing1():
> """orm method"""
> recs = sess.query(dm.Dealer).order_by('name').all()
>
> def timing2():
> """sql method"""
> dealers = dm.Dealer.__table__
> recs = engine.execute(select([dealers], order_by='name')).fetchall()
>
> def timing():
> t = timeit.Timer(timing1)
> print t.timeit(number=1)
> t = timeit.Timer(timing2)
> print t.timeit(number=1)
>
> if __name__ == "__main__":
> db.start(DATABASE)
> from common.database import engine
> sess = db.Session()
> timing()
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.