2

I'm using ad-hoc JavaScript map functions in couchdb-python through its query() function. Is there a way of getting the time the query takes to process?

I've tried timing the script, but it's pretty obvious to me that the time I'm getting is not correct. If I iterate over the ViewResult that the query() function returns and print all the results, I believe I get an answer that's closer to the truth, but I don't want the printing to be included in my timing..

Anyone got any ideas?

Thanks a bunch!

Robin
  • 193
  • 2
  • 9
  • I'm not at all familiar with the couchdb interface, but have you looked at the `timeit` module? Maybe that will help? – tMC May 19 '11 at 20:23
  • @tMC - Thank you very much for the suggestion, but I am afraid that it won't do the trick. The problem is that I seemingly have to do something with the ViewResult in order to get any time to measure. In pymongo (for MongoDB) I can do explain()['millis'] to get the milliseconds without having to iterate over the resultset. The best solution I've come up with so far is iterating over the ViewResult and doing _pass_ in the loop, but that's not very pretty and I really want to avoid iterating altogether. – Robin May 19 '11 at 20:45

2 Answers2

0

Use view() function to run permanent views in database. It is more efficient. In many cases, temporary may be very costly.

Shnkc
  • 2,108
  • 1
  • 27
  • 35
0

This is how I time things in my applications.

from datetime import *

lastTime = datetime.now()
dosomestuff()
pollTime = datetime.now()

diff = pollTime - lastTime
print diff.total_seconds()
#or if not python2.7 (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
Michael Dillon
  • 31,973
  • 6
  • 70
  • 106