[Checkins] SVN: mongopersist/trunk/src/mongopersist/performance.py print ops/second, added cache performance testing

Adam Groszer cvs-admin at zope.org
Tue Mar 5 14:58:01 UTC 2013


Log message for revision 130032:
  print ops/second, added cache performance testing

Changed:
  U   mongopersist/trunk/src/mongopersist/performance.py

-=-
Modified: mongopersist/trunk/src/mongopersist/performance.py
===================================================================
--- mongopersist/trunk/src/mongopersist/performance.py	2013-03-05 14:43:09 UTC (rev 130031)
+++ mongopersist/trunk/src/mongopersist/performance.py	2013-03-05 14:58:00 UTC (rev 130032)
@@ -56,6 +56,17 @@
 class Person2(Person):
     pass
 
+
+def printResult(text, t1, t2, count=None):
+    dur = t2-t1
+    text += ':'
+    ops = ''
+    if count:
+        ops = "%d ops/second" % (count / dur)
+
+    print '%-20s %.4f secs %s' % (text, dur, ops)
+
+
 def run_basic_crud(options):
     conn = pymongo.Connection('localhost', 27017, tz_aware=False)
     dm = datamanager.MongoDataManager(
@@ -75,11 +86,11 @@
             people[None] = klass('Mr Number %.5i' %idx, random.randint(0, 100))
         transaction.commit()
         t2 = time.time()
-        print 'Insert:       %.4f secs' % (t2-t1)
-
+        printResult('Insert', t1, t2, options.size)
     else:
         people = dm.root['people']
 
+    peopleCnt = len(people)
     # Profile slow read
     transaction.begin()
     t1 = time.time()
@@ -88,7 +99,7 @@
     #    '[people[name].name for name in people]', globals(), locals())
     t2 = time.time()
     transaction.commit()
-    print 'Slow Read:        %.4f secs' % (t2-t1)
+    printResult('Slow Read', t1, t2, peopleCnt)
 
     # Profile fast read (values)
     transaction.begin()
@@ -98,7 +109,7 @@
     #    '[person.name for person in people.find()]', globals(), locals())
     t2 = time.time()
     transaction.commit()
-    print 'Fast Read (values): %.4f secs' % (t2-t1)
+    printResult('Fast Read (values)', t1, t2, peopleCnt)
 
     # Profile fast read
     transaction.begin()
@@ -108,8 +119,19 @@
     #    '[person.name for person in people.find()]', globals(), locals())
     t2 = time.time()
     transaction.commit()
-    print 'Fast Read (find):   %.4f secs' % (t2-t1)
+    printResult('Fast Read (find)', t1, t2, peopleCnt)
 
+    # Profile object caching
+    transaction.begin()
+    t1 = time.time()
+    [person for person in people.values()]
+    [person.name for person in people.values()]
+    #cProfile.runctx(
+    #    '[person.name for person in people.values()]', globals(), locals())
+    t2 = time.time()
+    transaction.commit()
+    printResult('Fast Read (caching)', t1, t2, peopleCnt*2)
+
     if options.modify:
         # Profile modification
         t1 = time.time()
@@ -122,7 +144,7 @@
         #cProfile.runctx(
         #    'modify()', globals(), locals())
         t2 = time.time()
-        print 'Modification:     %.4f secs' % (t2-t1)
+        printResult('Modification', t1, t2, peopleCnt)
 
     if options.delete:
         # Profile deletion
@@ -131,7 +153,7 @@
             del people[name]
         transaction.commit()
         t2 = time.time()
-        print 'Deletion:         %.4f secs' % (t2-t1)
+        printResult('Deletion', t1, t2, peopleCnt)
 
 parser = optparse.OptionParser()
 parser.usage = '%prog [options]'



More information about the checkins mailing list