How to benchmark the FPS during playback

102 views
Skip to first unread message

Chi Ngai Lai

unread,
Nov 13, 2014, 3:04:39 PM11/13/14
to python_in...@googlegroups.com
Hi All,

I'm going  to write a script, which I want a realtime FPS value during the scene playback. 

I've tried the following codes, which were not worked for me. 

# specify how many times for playing
cmds.playbackOptions(loop='once')
# scrub the time cursor to frame 1
cmds.currentTime(1)
# begin to play

# make sure the scene is playing, then query for the realtime fps value
if cmds.play(q=True, st=True):
    print cmds.playbackOptions(fps=True)

Result: it only print 0.0 at the beging, then it stops printing fps values, and the scene was continue playing.

I've to manually keep executing those 2 lines of "if" codes, then it could keep printing the realtime fps value for me. 

But I want it automatically keep printing the fps values for me during the playback. 

Any thoughts? Much appreciate in advance. :)

Cheers,
Parker




Marcus Ottosson

unread,
Nov 15, 2014, 6:44:28 AM11/15/14
to python_in...@googlegroups.com

As you haven’t gotten a reply, I’ll share what I was thinking at first.

If you count the time between the frames, you can calculate your own fps.

import time

time_before = time.time()

# your code here
time.sleep(0.1)  # Pretend it takes a tenth of a second per frame

time_after = time.time()
time_delta = time_after - time_before
fps = 1.0 / time_delta

print "%f fps" % fps

Which prints, around:

9.30343 fps

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/86e30ad5-e448-42dd-b577-ef5a9b6925a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Chi Ngai Lai

unread,
Nov 15, 2014, 10:22:11 AM11/15/14
to python_in...@googlegroups.com
Hi Marcus,

Thank you for your reply!

Actually I used the similar method to write a function yesterday, and I would like to share the codes here. 

def getFPS(startFrame, totalFrames):     
cmds.currentTime(startFrame)
startTime = time.time()
for i in range(startFrame,startFrame+totalFrames):
   cmds.currentTime(i)
fps = totalFrames/(time.time()-startTime)
return fps 

I consider this is the workaround solution, and I just wondering whether there were any API Class could do this? 

Thanks,
Parker
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages