Commits

Hakan Ardo committed 98f94d3

measure fps, pypy is 70 times faster than cpython here

  • Participants
  • Parent commits b58ba74

Comments (0)

Files changed (2)

talk/dls2012/demo/demo.py

 from subprocess import call, Popen
-import os, time, re
+import os, time, re, sys
 
 class Vim(object):
     def __init__(self, *args):
         self.send('<ESC>:q!<CR>')
 
 def pause(msg=''):
-    print
+    print "\n"
     print msg
-    raw_input('Press ENTER')
+    raw_input('Press ENTER\n')
 
 def demo():
     with open('analytics.py', 'w') as fd:
     def update(self, frame):
         view(frame)
 """
-    runner = Popen(['pypy', 'run.py', 'demo.avi'])
+    runner = Popen([sys.executable, 'run.py', 'demo.avi'])
     vim = Vim('analytics.py')
 
     pause("We'r looking at the input and output of this Tracker object that\n" + 

talk/dls2012/demo/run.py

 from io import mplayer, view
 from analytics import Tracker
-import sys
+import sys, time
 
 if len(sys.argv) > 1:
     fn = sys.argv[1]
 else:
     fn = 'demo.avi'
 
+t0 = time.time()
+fcnt = 0
+
 tracker = Tracker()
 while True:
     for img in mplayer(fn):
         view(img, 'Input')
         tracker.update(img)
 
+        t1 = time.time()
+        if t1 - t0 > 1:
+            print >>sys.stderr, '\r%f fps' % (fcnt / (t1-t0)),
+            t0 = t1
+            fcnt = 0
+        fcnt += 1
 
+