Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on rdCodeTimer groupName,pointName
- -- Allows easy timing of numerous code portions at run-time.
- -- To use, insert: rdCodeTimer(groupName,pointName) throughout your code.
- -- eg: a groupName might be, "car physics", and point names might be "start", "wall collision", "floor collision", "model update"
- -- It is a good idea for the first point name in any group to be called "start", and each subsequent point name to describe
- -- the process that occurred to that point.
- -- When testing, allow to run for a number of frames, to get a good number of readings for averaging, then hold shift-T to
- -- get an alert box containing the timer results.
- global RDcodeTimer_lms,RDcodeTimes
- cms = the milliseconds
- if not listp(RDcodeTimes) then
- RDcodeTimes = [:]
- RDcodeTimer_lms = [:]
- end if
- lms = RDcodeTimer_lms.getaprop(groupName)
- if voidp(lms) then lms = cms
- if not listp(RDcodeTimes.getaprop(groupName)) then
- RDcodeTimes.setaprop(groupName,[:])
- end if
- if not listp(RDcodeTimes[groupName].getaprop(pointName)) then
- RDcodeTimes[groupName].setaprop(pointName,[#start])
- else
- RDcodeTimes[groupName][pointName].add(cms-lms)
- if RDcodeTimes[groupName][pointName].count > 100 then
- RDcodeTimes[groupName][pointName].deleteAt(1)
- end if
- end if
- if keypressed("t") and the shiftDown then
- repeat with gn = 1 to RDcodeTimes.count
- groupName = RDcodeTimes.getpropat(gn)
- atxt = "Breakdown for '"&groupName&"'"&return
- total = 0
- repeat with n=1 to RDcodeTimes[groupName].count
- readingName = RDcodeTimes[groupName].getpropat(n)
- if readingName<>"start" then
- repeat with reading in RDcodeTimes[groupName][n]
- avg = avg + reading
- end repeat
- avg = avg / float(RDcodeTimes[groupName][n].count)
- avg = floatPrecisionString(avg,3)
- cline = readingName&":"&avg&"ms"-- ("&RDcodeTimes[groupName][n].count&" readings)"
- oput cline
- atxt = atxt & cline & return
- total = total + avg
- end if
- end repeat
- atxt = atxt & "TOTAL:"&total&"ms" & return
- safealert(atxt)
- end repeat
- repeat while keypressed("t")
- end repeat
- RDcodeTimes = [:]
- RDcodeTimer_lms = [:]
- halt
- end if
- RDcodeTimer_lms.setaprop(groupName,the milliseconds)
- end
Advertisement
Add Comment
Please, Sign In to add comment