duck

duck

Mar 1st, 2011
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1.  
  2.  
  3.  
  4. on rdCodeTimer groupName,pointName
  5.  
  6.   -- Allows easy timing of numerous code portions at run-time.
  7.   -- To use, insert: rdCodeTimer(groupName,pointName) throughout your code.
  8.  
  9.   -- eg: a groupName might be, "car physics", and point names might be "start", "wall collision", "floor collision", "model update"
  10.  
  11.   -- It is a good idea for the first point name in any group to be called "start", and each subsequent point name to describe
  12.   -- the process that occurred to that point.
  13.  
  14.   -- When testing, allow to run for a number of frames, to get a good number of readings for averaging, then hold shift-T to
  15.   -- get an alert box containing the timer results.
  16.  
  17.   global RDcodeTimer_lms,RDcodeTimes
  18.  
  19.   cms = the milliseconds
  20.  
  21.   if not listp(RDcodeTimes) then
  22.     RDcodeTimes = [:]
  23.     RDcodeTimer_lms = [:]
  24.   end if
  25.  
  26.   lms = RDcodeTimer_lms.getaprop(groupName)
  27.   if voidp(lms) then lms = cms
  28.  
  29.  
  30.   if not listp(RDcodeTimes.getaprop(groupName)) then
  31.     RDcodeTimes.setaprop(groupName,[:])
  32.   end if
  33.  
  34.   if not listp(RDcodeTimes[groupName].getaprop(pointName)) then
  35.     RDcodeTimes[groupName].setaprop(pointName,[#start])
  36.   else
  37.     RDcodeTimes[groupName][pointName].add(cms-lms)
  38.     if RDcodeTimes[groupName][pointName].count > 100 then
  39.       RDcodeTimes[groupName][pointName].deleteAt(1)
  40.     end if
  41.   end if
  42.  
  43.   if keypressed("t") and the shiftDown then
  44.    
  45.     repeat with gn = 1 to RDcodeTimes.count
  46.       groupName = RDcodeTimes.getpropat(gn)
  47.       atxt = "Breakdown for '"&groupName&"'"&return
  48.       total = 0
  49.       repeat with n=1 to RDcodeTimes[groupName].count
  50.        
  51.         readingName = RDcodeTimes[groupName].getpropat(n)
  52.        
  53.         if readingName<>"start" then
  54.          
  55.           repeat with reading in RDcodeTimes[groupName][n]
  56.             avg = avg + reading
  57.           end repeat
  58.           avg = avg / float(RDcodeTimes[groupName][n].count)
  59.           avg = floatPrecisionString(avg,3)
  60.           cline = readingName&":"&avg&"ms"-- ("&RDcodeTimes[groupName][n].count&" readings)"
  61.          oput cline
  62.          atxt = atxt & cline & return
  63.          total = total + avg
  64.        end if
  65.        
  66.      end repeat
  67.      atxt = atxt & "TOTAL:"&total&"ms" & return
  68.      safealert(atxt)
  69.    end repeat
  70.    
  71.    
  72.    repeat while keypressed("t")
  73.    end repeat
  74.    
  75.    RDcodeTimes = [:]
  76.    RDcodeTimer_lms = [:]
  77.    
  78.    halt
  79.    
  80.  end if
  81.  
  82.  RDcodeTimer_lms.setaprop(groupName,the milliseconds)
  83.  
  84. end
Advertisement
Add Comment
Please, Sign In to add comment