Advertisement
FocusedWolf

TimeCode

Jul 13th, 2011
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. local currTime = os.clock()
  2.  
  3. ... code to time ...
  4.  
  5. local deltaT = os.clock() - currTime
  6. if deltaT > 0 then
  7.  
  8. //discard the "0" times and you should see some times print to console... I think it's the game or lua (not so much the code) that's resulting in these barely noticable delays. Maybe this is not a useful means to determine what is optimal.
  9.  
  10.     Print(ToString(deltaTime))
  11. end
  12.  
  13. //////////// I'm not sure why but Shared.GetTime() in place of os.clock() just gives me 0's
  14.  
  15. But i did find an interesting way to about about doing this:
  16.  
  17. function YourModClass:Update(deltaTime)
  18.  
  19. end
  20.  
  21. The deltaTime of your Update function can be used to time code.
  22.  
  23. I suggest having a test-mod on hand for doing the following:
  24.  
  25. function YourModClass:Update(deltaTime)
  26.  
  27.     for i = 1,1000 do
  28.         SlowCode()
  29.     end
  30.  
  31.     Print(deltaTime)
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement