5

I'm attempting to benchmark the speed of several different queries which return the same thing on Django 1.4 with Postgres. Unfortunately, if I use:

 import logging
 l = logging.getLogger('django.db.backends')
 l.setLevel(logging.DEBUG)
 l.addHandler(logging.StreamHandler())

Two equivalent or similar queries, end up getting deferred to the Query cache. Any way I can clear this cache or have a better way of comparing the speed of two queries?

9
  • I would most definitely like to know as well. +1 Commented Jul 19, 2013 at 6:02
  • 1
    Why not install django-debug-toolbar Commented Jul 19, 2013 at 6:03
  • Already have django-debug-toolbar installed, but it does not work in many instances (ie. AJAX requests), and is not really efficient in benchmarking queries since I need to load them into a view and manually test. Also, if you run two of the same queries, since its cached, the time for the second query will be significantly shorter. Commented Jul 19, 2013 at 6:08
  • You should take a look at stackoverflow.com/questions/3346124/… Commented Jul 19, 2013 at 6:14
  • You should never time ajax requests since they are async by nature. using the timeit module in python would help you time a view's execution time though. Commented Jul 19, 2013 at 6:28

1 Answer 1

5

For my analysis I used something like this:

from django import db
for query in db.connections['default'].queries:
    print query, query['time']
Sign up to request clarification or add additional context in comments.

2 Comments

This solution has the same issue as mine and the above suggestion, which is that since Django caches querysets, if you run the same or similar operation twice within a fixed period of time, the retrieval times will significantly differ ):

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.