]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added hotshot points into unit test, localizes profiling to just the query.select...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 May 2007 21:29:50 +0000 (21:29 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 May 2007 21:29:50 +0000 (21:29 +0000)
0.4 branch now has 18% fewer function calls for the same test.

test/perf/masseagerload.py

index 23b4c5ba1b78046994a2786a8f8260bffbc53df6..01aa7cf9ed0be8255fdaa9ba6eeeb88c66f06eb4 100644 (file)
@@ -5,11 +5,13 @@ import StringIO
 import testbase
 import gc
 import time
+import hotshot
+import hotshot.stats
 
 db = testbase.db
 
-NUM = 25000
-DIVISOR = 500
+NUM = 500
+DIVISOR = 50
 
 class LoadTest(AssertMixin):
     def setUpAll(self):
@@ -28,13 +30,13 @@ class LoadTest(AssertMixin):
     def setUp(self):
         clear_mappers()
         l = []
-        for x in range(1,NUM/DIVISOR):
+        for x in range(1,NUM/DIVISOR + 1):
             l.append({'item_id':x, 'value':'this is item #%d' % x})
         #print l
         items.insert().execute(*l)
-        for x in range(1, NUM/DIVISOR):
+        for x in range(1, NUM/DIVISOR + 1):
             l = []
-            for y in range(1, NUM/(NUM/DIVISOR)):
+            for y in range(1, NUM/(NUM/DIVISOR) + 1):
                 z = ((x-1) * NUM/(NUM/DIVISOR)) + y
                 l.append({'sub_id':z,'value':'this is iteim #%d' % z, 'parent_id':x})
             #print l
@@ -45,12 +47,16 @@ class LoadTest(AssertMixin):
         mapper(Item, items, properties={'subs':relation(SubItem, lazy=False)})
         mapper(SubItem, subitems)
         sess = create_session()
-        now = time.time()
+        prof = hotshot.Profile("masseagerload.prof")
+        prof.start()
         query = sess.query(Item)
         l = query.select()
         print "loaded ", len(l), " items each with ", len(l[0].subs), "subitems"
-        total = time.time() -now
-        print "total time ", total
+        prof.stop()
+        prof.close()
+        stats = hotshot.stats.load("masseagerload.prof")
+        stats.sort_stats('time', 'calls')
+        stats.print_stats()
         
 if __name__ == "__main__":
     testbase.main()