2010
05.19
05.19
Which is the fastest way to do this or that? Why not try them all and benchmark! 🙂
All you need to do is lock at the time.clock()…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# We need this for OS detection: from platform import system as OStype # Step 1: tick, tock... from time import clock start_time = clock() # Step 2: ??? # (You do your procedures here.) # You NEED to do SOMETHING. Don't leave this blank!! # Here's a filler of nothingness: from time import sleep sleep(0.05) # Step 3: calculate duration timeTaken = clock() - start_time # In Windows clock() returns seconds but in Linux it's milliseconds, so: units = ["seconds" if OStype() is "Windows" else "milliseconds"][0] msg = "It took "+str(timeTaken)+" "+units+" to process your code." Application.LogMessage(msg) # if you're in Softimage, # otherwise use print() or whatever. |
I tried to make the snippet above as generic as possible, but if you’re using Python in Softimage, you can use XSIUtils.IsWindowsOS() for detecting Windows instead of my OStype stuff.
Or just make a decorator for timming your code, python is awesome 🙂