Include 60Hz bullet estimate.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 17 Mar 2010 06:58:41 +0000 (23:58 -0700)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 17 Mar 2010 06:58:41 +0000 (23:58 -0700)
bulletml-runner

index 96b1efbcc717ae33e8e7727c7a41ce4a282f551f..21ba80e0f5da332f6b2e7b2c4bcc3eff89e7a6a0 100755 (executable)
@@ -2,6 +2,7 @@
 
 import os
 import sys
+import time
 
 import pygame
 
@@ -67,6 +68,8 @@ def main(argv):
 
             if not paused or go:
 
+                start = time.time()
+                count = len(active)
                 for obj in list(active):
                     new = obj.step()
                     total += len(new)
@@ -75,11 +78,16 @@ def main(argv):
                         or not (-50 < obj.x < 350)
                         or not (-50 < obj.y < 350)):
                         active.remove(obj)
+                elapsed = time.time() - start
 
                 frames += 1
                 if frames % 100 == 0:
+                    seconds_per_bullet = elapsed / count
+                    bullets_per_second = count / elapsed
                     print "  Processing: %04d: %d bullets, %d active." % (
-                        frames, total, len(active))
+                        frames, total, count)
+                    print "  %g seconds per bullet (60Hz max: %g)." % (
+                        seconds_per_bullet, bullets_per_second / 60)
 
             screen.fill([0, 0, 0])
             for obj in active:
@@ -94,9 +102,8 @@ def main(argv):
                         x -= 1
                         y -= 1
                         screen.blit(bullet, [x, y])
-            pygame.display.flip()
-
             clock.tick(60)
+            pygame.display.flip()
 
         print "  Finished: %04d: %d bullets." % (frames, total)